跳转到内容

插屏广告

插屏广告一般采用全屏或整页形式,会暂时覆盖应用的整个界面,通常出现在应用自然的暂停或过渡节点,例如游戏关卡完成后、主要视图切换时等。

以下各节将向您介绍如何加载和显示插屏广告。

加载插屏广告

要加载插屏广告,请首先创建一个对应您广告单元的 MaxInterstitialAd 对象。 然后调用该对象的 loadAd() 方法。 实现 MaxAdListener以便在广告就绪时收到通知 (您也可以收到其他广告相关事件的通知)。

public class ExampleActivity extends Activity
implements MaxAdListener
{
private MaxInterstitialAd interstitialAd;
private int retryAttempt;
void createInterstitialAd()
{
interstitialAd = new MaxInterstitialAd( "«ad-unit-ID»" );
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();
}
}

展示插屏广告

要展示插屏广告,请在刚才创建的 MaxInterstitialAd 实例对象上调用 showAd( this )

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

锁屏广告

AppLovin MAX SDK 提供了可在锁屏上展示插页广告的API。 此集成的用例包括音频应用程序,它们通常出现在锁定屏幕上。

加载锁屏广告

When you load an interstitial ad to display on the lock screen, 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»" );
interstitialAd.setExtraParameter( "container_view_ads", "true" );
interstitialAd.setListener( this );
// Load the first ad
interstitialAd.loadAd();
}
// MAX Ad Listener
}

显示锁屏广告

要显示锁屏广告,请在广告中使用 ViewGroup 来调用 showAd(…)

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

中介网络支持

支持该功能的网络是AppLovin Bidding和AppLovin Exchange。

为适配器添加自定义支持

要为自定义适配器或 AppLovin 的开源适配器添加支持,请重写下列 showInterstitialAd(…) 方法。

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