Java Code Examples for com.applovin.sdk.AppLovinSdk#getInstance()

The following examples show how to use com.applovin.sdk.AppLovinSdk#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InlineCarouselCardView.java    From Android-SDK-Demo with MIT License 6 votes vote down vote up
public void setUpView()
{
    this.uiHandler = new Handler( Looper.getMainLooper() );

    final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
    inflater.inflate( R.layout.applovin_card_view, this, true );

    bindViews();

    renderActivityIndicator();

    if ( sdk == null )
    {
        sdk = AppLovinSdk.getInstance( getContext() );
    }

    sdk.getNativeAdService().precacheResources( ad, this );
}
 
Example 2
Source File: AppLovinUtils.java    From googleads-mobile-android-mediation with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server
 * parameters, or Android Manifest.
 */
public static AppLovinSdk retrieveSdk(Bundle serverParameters, Context context) {
  final String sdkKey =
      (serverParameters != null) ? serverParameters.getString(ServerParameterKeys.SDK_KEY) : null;
  final AppLovinSdk sdk;

  if (!TextUtils.isEmpty(sdkKey)) {
    sdk = AppLovinSdk.getInstance(sdkKey, new AppLovinSdkSettings(), context);
  } else {
    sdk = AppLovinSdk.getInstance(context);
  }

  sdk.setPluginVersion(BuildConfig.VERSION_NAME);
  sdk.setMediationProvider(AppLovinMediationProvider.ADMOB);
  return sdk;
}
 
Example 3
Source File: AppLovinCustomEventBanner.java    From SDK-Network-Adapters with MIT License 6 votes vote down vote up
/**
 * Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server parameters, or Android Manifest.
 */
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras, final Context context)
{
    final String sdkKey = serverExtras != null ? serverExtras.get( "sdk_key" ) : null;
    final AppLovinSdk sdk;

    if ( !TextUtils.isEmpty( sdkKey ) )
    {
        sdk = AppLovinSdk.getInstance( sdkKey, new AppLovinSdkSettings(), context );
    }
    else
    {
        sdk = AppLovinSdk.getInstance( context );
    }

    return sdk;
}
 
Example 4
Source File: AppLovinCustomEventNative.java    From SDK-Network-Adapters with MIT License 6 votes vote down vote up
/**
 * Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server parameters, or Android Manifest.
 */
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras, final Context context)
{
    final String sdkKey = serverExtras != null ? serverExtras.get( "sdk_key" ) : null;
    final AppLovinSdk sdk;

    if ( !TextUtils.isEmpty( sdkKey ) )
    {
        sdk = AppLovinSdk.getInstance( sdkKey, new AppLovinSdkSettings(), context );
    }
    else
    {
        sdk = AppLovinSdk.getInstance( context );
    }

    return sdk;
}
 
Example 5
Source File: AppLovinCustomEventRewardedVideo.java    From SDK-Network-Adapters with MIT License 6 votes vote down vote up
/**
 * Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server parameters, or Android Manifest.
 */
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras, final Context context)
{
    final String sdkKey = serverExtras != null ? serverExtras.get( "sdk_key" ) : null;
    final AppLovinSdk sdk;

    if ( !TextUtils.isEmpty( sdkKey ) )
    {
        sdk = AppLovinSdk.getInstance( sdkKey, new AppLovinSdkSettings(), context );
    }
    else
    {
        sdk = AppLovinSdk.getInstance( context );
    }

    return sdk;
}
 
Example 6
Source File: AppLovinCustomEventInterstitial.java    From SDK-Network-Adapters with MIT License 6 votes vote down vote up
/**
 * Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server parameters, or Android Manifest.
 */
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras, final Context context)
{
    final String sdkKey = serverExtras != null ? serverExtras.get( "sdk_key" ) : null;
    final AppLovinSdk sdk;

    if ( !TextUtils.isEmpty( sdkKey ) )
    {
        sdk = AppLovinSdk.getInstance( sdkKey, new AppLovinSdkSettings(), context );
    }
    else
    {
        sdk = AppLovinSdk.getInstance( context );
    }

    return sdk;
}
 
Example 7
Source File: AppLovinCustomEventInterstitial.java    From SDK-Network-Adapters with MIT License 6 votes vote down vote up
@Override
public void showInterstitial()
{
    final AppLovinAd preloadedAd = dequeueAd( zoneId );
    if ( preloadedAd != null )
    {
        final AppLovinSdk sdk = AppLovinSdk.getInstance( context );

        final AppLovinInterstitialAdDialog interstitialAd = AppLovinInterstitialAd.create( sdk, context );
        interstitialAd.setAdDisplayListener( this );
        interstitialAd.setAdClickListener( this );
        interstitialAd.setAdVideoPlaybackListener( this );
        interstitialAd.showAndRender( preloadedAd );
    }
    else
    {
        log( ERROR, "Failed to show an AppLovin interstitial before one was loaded" );
        listener.onAdFailedToLoad( AdRequest.ERROR_CODE_INTERNAL_ERROR );
    }
}
 
Example 8
Source File: AppLovinCustomEventNative.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server
 * parameters, or Android Manifest.
 */
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras,
    final Context context) {
  final String sdkKey = serverExtras != null ? serverExtras.get("sdk_key") : null;
  final AppLovinSdk sdk;

  if (!TextUtils.isEmpty(sdkKey)) {
    sdk = AppLovinSdk.getInstance(sdkKey, new AppLovinSdkSettings(), context);
  } else {
    sdk = AppLovinSdk.getInstance(context);
  }

  return sdk;
}
 
Example 9
Source File: NativeAdCarouselUIActivity.java    From Android-SDK-Demo with MIT License 5 votes vote down vote up
public void loadNativeAds(final int numAdsToLoad)
{
    final AppLovinSdk sdk = AppLovinSdk.getInstance( getApplicationContext() );
    sdk.getNativeAdService().loadNativeAds( numAdsToLoad, new AppLovinNativeAdLoadListener()
    {
        @Override
        public void onNativeAdsLoaded(final List list)
        {
            // Native ads loaded; do something with this, e.g. render into your custom view.

            runOnUiThread( new Runnable()
            {
                @Override
                public void run()
                {
                    log( "Native ad loaded, assets not retrieved yet." );

                    nativeAd = (AppLovinNativeAd) list.get( 0 );
                    precacheButton.setEnabled( true );
                }
            } );
        }

        @Override
        public void onNativeAdsFailedToLoad(final int errorCode)
        {
            // Native ads failed to load for some reason, likely a network error.
            // Compare errorCode to the available constants in AppLovinErrorCodes.

            log( "Native ad failed to load with error code " + errorCode );

            if ( errorCode == AppLovinErrorCodes.NO_FILL )
            {
                // No ad was available for this placement
            }
            // else if (errorCode == .... ) { ... }
        }
    } );
}
 
Example 10
Source File: MainActivity.java    From Android-SDK-Demo with MIT License 5 votes vote down vote up
/**
 * Toggling the sdk mute setting will affect whether your video ads begin in a muted state or not.
 */
private void toggleMute()
{
    AppLovinSdk sdk = AppLovinSdk.getInstance( this );
    sdk.getSettings().setMuted( !sdk.getSettings().isMuted() );
    muteToggleMenuItem.setIcon( getMuteIconForCurrentSdkMuteSetting() );
}
 
Example 11
Source File: MainActivity.java    From Android-SDK-Demo with MIT License 5 votes vote down vote up
private Drawable getMuteIconForCurrentSdkMuteSetting()
{
    AppLovinSdk sdk = AppLovinSdk.getInstance( this );
    int drawableId = sdk.getSettings().isMuted() ? R.drawable.mute : R.drawable.unmute;

    if ( Build.VERSION.SDK_INT >= 22 )
    {
        return getResources().getDrawable( drawableId, getTheme() );
    }
    else
    {
        return getResources().getDrawable( drawableId );
    }
}
 
Example 12
Source File: AppLovinCarouselView.java    From Android-SDK-Demo with MIT License 4 votes vote down vote up
public AppLovinCarouselView(Context context, AttributeSet attrs, int defStyleAttr)
{
    this( context, attrs, defStyleAttr, AppLovinSdk.getInstance( context ), null );
}
 
Example 13
Source File: NativeAdRecyclerViewActivity.java    From Android-SDK-Demo with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate( savedInstanceState );

    setContentView( R.layout.activity_native_ad_recycler_view );
    recyclerView = (RecyclerView) findViewById( R.id.nativeAdsRecyclerView );

    // Load an initial batch of native ads.
    // In a real app, you'd ideally load smaller batches, and load more as the user scrolls.
    final AppLovinSdk sdk = AppLovinSdk.getInstance( this );
    final Activity activityRef = this;

    final AppLovinNativeAdService nativeAdService = sdk.getNativeAdService();
    nativeAdService.loadNativeAds( 10, new AppLovinNativeAdLoadListener()
    {
        @Override
        public void onNativeAdsLoaded(final List /* <AppLovinNativeAd> */ list)
        {
            runOnUiThread( new Runnable()
            {
                @Override
                public void run()
                {
                    renderRecyclerView( list );
                    retrieveImageResources( nativeAdService, list );
                }
            } );
        }

        @Override
        public void onNativeAdsFailedToLoad(final int errorCode)
        {
            runOnUiThread( new Runnable()
            {
                @Override
                public void run()
                {
                    Toast.makeText( activityRef, "Failed to load native ads: " + errorCode, Toast.LENGTH_LONG ).show();
                }
            } );
        }
    } );
}
 
Example 14
Source File: AppLovinCustomEventInterstitial.java    From SDK-Network-Adapters with MIT License 4 votes vote down vote up
@Override
public void requestInterstitialAd(final Context context, final CustomEventInterstitialListener listener, final String serverParameter, final MediationAdRequest mediationAdRequest, final Bundle customEventExtras)
{
    log( DEBUG, "Requesting AppLovin interstitial..." );

    // SDK versions BELOW 7.2.0 require a instance of an Activity to be passed in as the context
    if ( AppLovinSdk.VERSION_CODE < 720 && !( context instanceof Activity ) )
    {
        log( ERROR, "Unable to request AppLovin interstitial. Invalid context provided." );
        listener.onAdFailedToLoad( AdRequest.ERROR_CODE_INVALID_REQUEST );

        return;
    }

    // Store parent objects
    this.listener = listener;
    this.context = context;

    final AppLovinSdk sdk = AppLovinSdk.getInstance( context );
    sdk.setPluginVersion( "AdMob-2.2.1" );

    // Zones support is available on AppLovin SDK 7.5.0 and higher
    if ( AppLovinSdk.VERSION_CODE >= 750 && customEventExtras != null && customEventExtras.containsKey( "zone_id" ) )
    {
        zoneId = customEventExtras.getString( "zone_id" );
    }
    else
    {
        zoneId = DEFAULT_ZONE;
    }

    // Check if we already have a preloaded ad for the given zone
    final AppLovinAd preloadedAd = dequeueAd( zoneId );
    if ( preloadedAd != null )
    {
        log( DEBUG, "Found preloaded ad for zone: {" + zoneId + "}" );
        adReceived( preloadedAd );
    }
    else
    {
        // If this is a default Zone, load the interstitial ad normally
        if ( DEFAULT_ZONE.equals( zoneId ) )
        {
            sdk.getAdService().loadNextAd( AppLovinAdSize.INTERSTITIAL, this );
        }
        // Otherwise, use the Zones API
        else
        {
            sdk.getAdService().loadNextAdForZoneId( zoneId, this );
        }
    }
}