AI Search

插页式广告

我们支持静态插页式广告和视频插页式广告。请按照以下说明设置插页式广告。

笔记

您可以在这里查看GitHub上插页式广告集成的代码示例

设置插页式广告

  1. 从左侧导航栏中选择“库存” >“库存设置”。
  2. 搜索您想要为其创建广告位的应用或网站,然后点击+ 添加广告位
  3. 点击“选择广告单元”,然后选择“插页式广告”
  4. 点击“添加植入位置”开始设置您的插膜设置。创建插膜植入位置后,您可以看到植入位置 ID。

     

在您的应用中添加插页式广告

创建插页式广告

要创建插页式广告,请创建一个实例InMobiInterstitial

  • Java
  • Kotlin

Java

InMobiInterstitial interstitialAd = new InMobiInterstitial(InterstitialAdsActivity.this, 1471550843414L, 
mInterstitialAdEventListener);

Kotlin

这里mInterstitialAdEventListener是抽象类的一个实现InterstitialAdEventListener。创建插页式广告必须提供此抽象类的实现。

警告

  • InMobiInterstitial 类不是线程安全的。必须在 UI 线程上创建插页式广告实例。
  • 同样,此实例上的所有方法都必须在 UI 线程上调用。否则会导致不可预测的行为,并可能影响您使用 InMobi 进行盈利的能力。
  • 创建未进行 SDK 初始化的 InMobi Interstitial 对象会引发异常。

InterstitialAdEventListener抽象类允许您监听插页式广告的关键生命周期事件。您应该监听这些事件,以确保您的应用程序能够正确处理各种生命周期转换。

Java

/**
* Listener for receiving notifications during the lifecycle of an interstitial.
*/
public abstract class InterstitialAdEventListener {
    /**  
     * Called to indicate that an ad was loaded and it can now be shown. This will always be called  
     * after the {@link ##onAdFetchSuccessful(InMobiInterstitial, AdMetaInfo)} callback.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which was loaded  
     * @param info Represents the ad meta information  
     */ 
    public void onAdLoadSucceeded(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {} 
    /**  
     * Callback to signal that a request to fetch an ad (by calling  
     * {@link InMobiInterstitial##load()} failed. The status code indicating the reason for failure  
     * is available as a parameter. You should call {@link InMobiInterstitial##load()} again to  
     * request a fresh ad.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which failed to load  
     * @param status Represents the {@link InMobiAdRequestStatus} status containing error reason  
     */ 
    public void onAdLoadFailed(@NonNull InMobiInterstitial ad, @NonNull InMobiAdRequestStatus status) {} 
    /**  
     * Called to indicate that an ad is available in response to a request for an ad (by calling  
     * {@link InMobiInterstitial##load()}. Note: This does not  
     * indicate that the ad can be shown yet. Your code should show an ad after the  
     * {@link ##onAdLoadSucceeded(InMobiInterstitial)} method is called. Alternately, if you do not  
     * want to handle this event, you must test if the ad is ready to be shown by checking the  
     * result of calling the {@link InMobiInterstitial##isReady()} method.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad for which ad content was received  
     * @param info Represents the ad meta information  
     */ 
    public void onAdFetchSuccessful(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {} 
    /**  
     * Called to indicate that an ad interaction was observed.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad on which user clicked  
     * @param params Represents the click parameters  
     */ 
    public void onAdClicked(@NonNull InMobiInterstitial ad, Map < Object, Object > params) {} 
    /**  
     * Called to indicate that the ad will be launching a fullscreen overlay.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which will display  
     */ 
    public void onAdWillDisplay(@NonNull InMobiInterstitial ad) {} 
    /**  
     * Called to indicate that the fullscreen overlay is now the topmost screen.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which is displayed  
     * @param info Represents the ad meta information  
     */ 
    public void onAdDisplayed(@NonNull InMobiInterstitial ad, @NonNull AdMetaInfo info) {} 
    /**  
     * Called to indicate that a request to show an ad (by calling {@link InMobiInterstitial##show()}  
     * failed. You should call {@link InMobiInterstitial##load()} to request for a fresh ad.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which failed to show  
     */ 
    public void onAdDisplayFailed(@NonNull InMobiInterstitial ad) {} 
    /**  
     * Called to indicate that the fullscreen overlay opened by the ad was closed.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad which was dismissed  
     */ 
    public void onAdDismissed(@NonNull InMobiInterstitial ad) {} 
    /**  
     * Called to indicate that the user may leave the application on account of interacting with the ad.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad  
     */ 
    public void onUserLeftApplication(@NonNull InMobiInterstitial ad) {} 
    /**  
     * Called to indicate that rewards have been unlocked.  
     *  
     * @param ad Represents the {@link InMobiInterstitial} ad for which rewards was unlocked  
     * @param rewards Represents the rewards unlocked  
     */ 
    public void onRewardsUnlocked(@NonNull InMobiInterstitial ad, Map < Object, Object > rewards) {} 
    /** 
     * Called to notify that inmobi has logged an impression for the ad 
     * @param ad     Represents the ad which was impressed 
     */ 
    public void onAdImpression(@NonNull InMobiInterstitial ad) { 
    } 
}

Kotlin

/**
* Listener for receiving notifications during the lifecycle of an interstitial.
*/
abstract class InterstitialAdEventListener : AdEventListener<inmobiinterstitial>() {
/**
    * Called to notify that an ad preload has failed.  
    *  
    ***Note** This notification is given only when you use `preload()` in  
    * [InMobiInterstitial.preloadManager]  
    *  
    * @param ad     Represents the [InMobiInterstitial] ad which was preloaded  
    * @param status Represents the [InMobiAdRequestStatus] status containing error reason  
    */  
open fun onAdFetchFailed(ad: InMobiInterstitial, status: InMobiAdRequestStatus) {}
/**
    * Called to indicate that the ad will be launching a fullscreen overlay.  
    *  
    * @param ad Represents the [InMobiInterstitial] ad which will display  
    */  
open fun onAdWillDisplay(ad: InMobiInterstitial) {}
/**
    * Called to indicate that the fullscreen overlay is now the topmost screen.  
    *  
    * @param ad   Represents the [InMobiInterstitial] ad which is displayed  
    * @param info Represents the meta info for the ad displayed  
    */  
open fun onAdDisplayed(ad: InMobiInterstitial, info: AdMetaInfo) {}
/**
    * Called to indicate that a request to show an ad (by calling [InMobiInterstitial.show]  
    * failed. You should call [InMobiInterstitial.load] to request for a fresh ad.  
    *  
    * @param ad Represents the [InMobiInterstitial] ad which failed to show  
    */  
open fun onAdDisplayFailed(ad: InMobiInterstitial) {}
/**
    * Called to indicate that the fullscreen overlay opened by the ad was closed.  
    *  
    * @param ad Represents the [InMobiInterstitial] ad which was dismissed  
    */  
open fun onAdDismissed(ad: InMobiInterstitial) {}
/**
    * Called to indicate that the user may leave the application on account of interacting with the ad.  
    *  
    * @param ad Represents the [InMobiInterstitial] ad  
    */  
open fun onUserLeftApplication(ad: InMobiInterstitial) {}
/**
    * Called to indicate that rewards have been unlocked.  
    *  
    * @param ad      Represents the [InMobiInterstitial] ad for which rewards was unlocked  
    * @param rewards Represents the rewards unlocked  
    */  
open fun onRewardsUnlocked(ad: InMobiInterstitial, rewards: Map<any, any="">) {}
/**
     * Called to notify that inmobi has logged an impression for the ad 
     * @param ad     Represents the ad which was impressed 
     */ 
open fun onAdImpression(ad: InMobiInterstitial) {}
}

正在加载插页式广告

要请求插页式广告,请调用实例load()上的相应方法InMobiInterstitial

Java

interstitialAd.load();

Kotlin

interstitialAd.load()

InterstitialAdEventListener抽象类会通知此方法的结果。如果广告请求成功,onAdFetchSuccessful(InMobiInterstitial, AdMetaInfo)则会生成一个事件。随后会生成另一个onAdLoadSucceeded事件onAdLoadFailed

如果事件被触发,则事件触发时传递的对象onAdLoadFailed会指示触发原因。InMobiAdRequestStatus

如果事件已生成,您可以在此后的任何时间通过调用实例onAdLoadSucceeded来显示广告show()InMobiInterstitial

笔记

在 SDK 生成事件后再次调用load()同一个插页式广告onAdLoadSucceeded并不能保证会从广告网络请求到新的广告。只有当之前的广告被 SDK 丢弃、广告过期或用户清除了应用数据和缓存时,才会获取到新的广告。

展示插页式广告

要显示插页式广告,可以在 SDK 生成事件后的任何时间show()调用实例。以下代码片段对此进行了说明。InMobiInterstitialonAdLoadSucceeded

Java

InMobiInterstitial interstitialAd;
InterstitialAdEventListener mInterstitialAdEventListener = new InterstitialAdEventListener() {
    // implementation for other events 
    // onAdFetchSuccessful, onAdLoadFailed, etc 
    @Override
    public void onAdLoadSucceeded(@NonNull InMobiInterstitial inMobiInterstitial, @NonNull AdMetaInfo info) {
        Log.d(TAG, "Ad can now be shown!");
        mCanShowAd = true;
    }
};
void init() {
    InMobiInterstitial interstitialAd = new InMobiInterstitial(GameActivity.this, 1471550843414 L, mInterstitialAdEventListener);
}
void prepareGameLevel() {
    interstitialAd.load();
}
void handleGameLevelCompleted() {
    If(mCanShowAd) interstitialAd.show();
}

Kotlin

val interstitialAd: InMobiInterstitial 
val mInterstitialAdEventListener = InterstitialAdEventListener() { 
   // implementation for other events 
   // onAdFetchSuccessful, onAdLoadFailed, etc 
   override fun onAdLoadSucceeded(inMobiInterstitial: InMobiInterstitial, info: AdMetaInfo) { 
       Log.d(TAG, "Ad can now be shown!") 
       mCanShowAd = true 
   } 
} 
fun init() { 
   val interstitialAd = InMobiInterstitial(this@GameActivity, 1471550843414L, mInterstitialAdEventListener) 
} 
fun prepareGameLevel() { 
   interstitialAd.load() 
} 
fun handleGameLevelCompleted() { 
   if(mCanShowAd) interstitialAd.show() 
} 

您的应用程序将通过抽象类收到此请求的结果通知InterstitialAdEventListener

如果广告可以显示,SDK 将通过调用接口通知您的代码onAdWillDisplay,然后在onAdDisplayed广告实际显示在屏幕上时调用该方法。

如果广告无法显示,onAdDisplayFailedSDK 会生成一个事件来通知您的应用程序广告无法显示。您可以load()再次调用该事件处理程序来请求显示新的广告。

当插页式广告被关闭时,您的应用程序将在回调中收到通知onAdDismissed

本页内容

最后更新于 : 10 Sep, 2026