インタースティシャル広告(Interstitial ads)
インタースティシャル広告の読み込み
インタースティシャル広告をロードするには、広告ユニットに対応する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(); }}
class ExampleActivity : Activity(), MaxAdListener{ private lateinit var interstitialAd: MaxInterstitialAd private var retryAttempt = 0.0
fun createInterstitialAd() { interstitialAd = MaxInterstitialAd( "«ad-unit-ID»", applicationContext ) interstitialAd.setListener( this )
// Load the first ad interstitialAd.loadAd() }
// MAX Ad Listener override fun onAdLoaded(maxAd: MaxAd) { // Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
// Reset retry attempt retryAttempt = 0.0 }
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) { // 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++ val delayMillis = TimeUnit.SECONDS.toMillis( Math.pow( 2.0, Math.min( 6.0, retryAttempt ) ).toLong() )
Handler().postDelayed( { interstitialAd.loadAd() }, delayMillis ) }
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) { // Interstitial ad failed to display. AppLovin recommends that you load the next ad. interstitialAd.loadAd() }
override fun onAdDisplayed(maxAd: MaxAd) {}
override fun onAdClicked(maxAd: MaxAd) {}
override fun onAdHidden(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 );}
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 ⋮}
⋮import androidx.lifecycle.LifecycleOwner⋮
class ExampleActivity : Activity(), MaxAdListener, LifecycleOwner{ private lateinit var adContainerView: FrameLayout private lateinit var interstitialAd: MaxInterstitialAd private var retryAttempt = 0.0
fun createInterstitialAd() { interstitialAd = MaxInterstitialAd( "«ad-unit-ID»", applicationContext ) 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 );}
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(…)
メソッドを上書きしてください。
@Overridepublic void showInterstitialAd(final MaxAdapterResponseParameters parameters, final ViewGroup containerView, final Lifecycle lifecycle, final Activity activity, final MaxInterstitialAdapterListener listener){ ⋮}