跳转到内容

Interstitial Ads

此内容尚不支持你的语言。

Loading an Interstitial Ad

To load an interstitial ad, first instantiate a MaxInterstitialAd object corresponding to your ad unit. Then call that object’s loadAd() method. Implement MaxAdListener so that you are notified when your ad is ready (you are also notified of other ad-related events).

public class ExampleActivity extends Activity
implements MaxAdListener
{
private MaxInterstitialAd interstitialAd;
private int retryAttempt;
void createInterstitialAd()
{
interstitialAd = new MaxInterstitialAd( "«ad-unit-ID»", getApplicationContext() );
interstitialAd.setListener( this );
// Load the first ad
interstitialAd.loadAd();
}
// MAX Ad Listener
@Override
public void onAdLoaded(final MaxAd maxAd)
{
// Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
// Reset retry attempt
retryAttempt = 0;
}
@Override
public void onAdLoadFailed(final String adUnitId, final MaxError error)
{
// Interstitial ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt++;
long delayMillis = TimeUnit.SECONDS.toMillis( (long) Math.pow( 2, Math.min( 6, retryAttempt ) ) );
new Handler().postDelayed( new Runnable()
{
@Override
public void run()
{
interstitialAd.loadAd();
}
}, delayMillis );
}
@Override
public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error)
{
// Interstitial ad failed to display. AppLovin recommends that you load the next ad.
interstitialAd.loadAd();
}
@Override
public void onAdDisplayed(final MaxAd maxAd) {}
@Override
public void onAdClicked(final MaxAd maxAd) {}
@Override
public void onAdHidden(final MaxAd maxAd)
{
// Interstitial ad is hidden. Pre-load the next ad
interstitialAd.loadAd();
}
}

Showing an Interstitial Ad

To show an interstitial ad, call showAd( this ) on the MaxInterstitialAd object that you created.

if ( interstitialAd.isReady() )
{
// `this` is the activity that will be used to show the ad
interstitialAd.showAd( this );
}

Lock Screen Ads

The AppLovin MAX SDK provides APIs with which you can display interstitial ads in the lock screen. Use cases for this integration include audio apps, which typically appear on the lock screen.

Loading a Lock Screen Ad

You load an interstitial ad to display on the lock screen in a similar way to how you would normally load an interstitial ad That process is described above. However, you need to set an extra parameter for the MaxInterstitialAd, and the Activity you pass in must implement the LifecycleOwner interface.

import androidx.lifecycle.LifecycleOwner;
public class ExampleActivity extends Activity
implements MaxAdListener, LifecycleOwner
{
private FrameLayout adContainerView;
private MaxInterstitialAd interstitialAd;
private int retryAttempt;
void createInterstitialAd()
{
interstitialAd = new MaxInterstitialAd( "«ad-unit-ID»", getApplicationContext() );
interstitialAd.setExtraParameter( "container_view_ads", "true" );
interstitialAd.setListener( this );
// Load the first ad
interstitialAd.loadAd();
}
// MAX Ad Listener
}

Showing a Lock Screen Ad

To show the lock screen interstitial ad, call showAd(…) with the ViewGroup in the ad.

if ( interstitialAd.isReady() )
{
// `this` is the activity that will be used to show the ad
interstitialAd.showAd( adContainerView, getLifecycle(), this );
}

Mediated Network Support

The networks that support this feature are AppLovin Bidding and AppLovin Exchange.

Adding Custom Support to Adapters

To add support into a custom adapter or one of our open source adapters, override the following showInterstitialAd(…) method.

@Override
public void showInterstitialAd(final MaxAdapterResponseParameters parameters,
final ViewGroup containerView,
final Lifecycle lifecycle,
final Activity activity,
final MaxInterstitialAdapterListener listener)
{
}