android - admob google play interstitial - 当广告未加载时显示内置 Activity

标签 android admob google-play-services interstitial

上下文: 使用最新的 Google Play admob... 我的 Activity 中有一个插页式广告,带有一个 adListener。

我想要实现的目标: 当广告无法加载时(因为设备正在使用 adblock,或者设备无法访问网络),我希望启动自定义 Activity (我已将其设置为看起来像自定义广告)。

我目前使用的代码来完成此任务:

interstitial.setAdListener(new AdListener()
    {
        @Override
        public void onAdLoaded()
        {
            displayInterstitial();
            super.onAdLoaded();
        }

        @Override
        public void onAdFailedToLoad(int errorCode)
        {
            Intent intent = new Intent(getApplicationContext(),
                    FailToLoadActivity.class);
            startActivity(intent);
            super.onAdFailedToLoad(errorCode);
        }

    });

我还尝试将这些 Intent... 行添加到 displayInterstitial() 方法中:

public void displayInterstitial()
{
    if (interstitial.isLoaded())
    {

        interstitial.show();
    }
    else
    {
        Intent intent = new Intent(getApplicationContext(),
                FailToLoadActivity.class);
        startActivity(intent);
    }
}

现在,我的自定义广告不再是在请求失败时立即显示,而是似乎在大约 30 秒后显示。 即使 Activity 被销毁,它也会执行此操作。

如何才能让此自定义广告在请求首次失败时立即显示,而在 Activity 被销毁时根本不显示?

/e 我注意到 logcat 中的一个条目:从现在开始安排广告刷新 60000 毫秒,我想将其更改为 5000 毫秒可以解决我的问题(同样,这是一个理论)...这是我可以更改的内容吗?

此外,我想保证当用户退出 Activity 时不会显示任何广告(我的自定义广告或网络转换的广告)(以防止任何应用外侵入性弹出窗口攻击我的用户)

最佳答案

摆脱你的 AdListener。

永远不想在收到插页式广告后立即显示它,也不想在插页式广告无法转换时立即显示您的自定义广告。

而是在应用程序中的自然断点处调用#displayInterstitial。这将确保您展示插页式广告或展示您的自定义广告。当您的 Activity 被销毁时,您将不会显示它。

您可以采取的另一种方法是设置内部广告并将其设置为中介流程中的后备选项。但我从未尝试过实现这一点。此外,您希望即使用户离线时也能正常工作,因此顶级方法是最好的。

关于android - admob google play interstitial - 当广告未加载时显示内置 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22511980/

相关文章:

android - android中的漫游检测

android - 带有自定义布局的 PreferenceFragmentCompat 在 API 28+ 上找不到工具栏

java - LayoutParams 需要 API 19?

ios - Firebase Analytics 事件不显示 ad_click 和 ad_impression 事件

使用 Google Plus : How do I GoogleApiClient. 再次连接的 Android 设计?

安卓对话框错误

Android:在广播接收器中使用 sharedPreferences

android - onFailedToReceiveAd(广告请求成功,但在使用 admob 和 adwhirl 时,由于缺少广告资源,没有返回广告

java - 我可以将 Google Play 服务添加到已发布的应用程序中吗?

android - Gradle 同步错误未能找到 : com. google.android.gms :play-services:6. 1.+'