跳转到内容

插屏广告

加载插屏广告

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

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();
}
}

展示插屏广告

要展示插屏广告,请在刚才创建的 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。 此集成的用例包括音频应用程序,它们通常出现在锁定屏幕上。

加载锁屏广告

在锁屏上加载插屏广告的方式与通常加载插屏广告的方式类似。该过程如上所述。 但是您需要为 MaxInterstitialAd 设置一个额外参数,且传入的 Activity 必须实现 LifecycleOwner 界面。

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
}

显示锁屏广告

要显示锁屏广告,请在广告中使用 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。

为适配器添加自定义支持

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

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