插页式Admob不起作用:未定义AFMA_ReceiveMessage [英] Interstitial Admob doesn't work : AFMA_ReceiveMessage is not defined

查看:81
本文介绍了插页式Admob不起作用:未定义AFMA_ReceiveMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种广告:横幅广告和非页内广告。第一个效果很好,但是在关闭我的应用程序之前,当我想显示插页式广告时,当我按下后退按钮(但我们不在乎该按钮)时。但是我的插页式广告无法正常工作,并且我的应用正在关闭,并在日志中出现以下错误:

I have two kind of ads : banner and interstitial. The first one works very well, but when I want to display an interstitial ad when I pressed the back button (but we don't care of the button), before closing my app. But my interstitial ad doesn't work and my app is closing with this error in log :

E/Ads(20984): JS: Uncaught ReferenceError: AFMA_ReceiveMessage is not defined (:1)

我不知道此错误是什么手段。
我浏览了互联网,它可能来自我的互联网连接。我的Wifi吗?
还是可能也来自Admob?

I don't know what this error means. I browsed internet, and it may comes from my internet connection. My Wifi ? Or it might comes from Admob aswell ?

我应该在其他连接更好的地方尝试吗?

Should I try in an other area with a better connexion ?

感谢您的帮助。

推荐答案

我的代码用于添加InterstitialAdd:

My code use to add InterstitialAdd:

public static void addInterstitialAd(final Activity context, final int id) {
    final InterstitialAd interstitial = new InterstitialAd(context);
    interstitial.setAdUnitId(context.getString(id));
    interstitial.loadAd(new AdRequest.Builder().build());
    interstitial.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // Call displayInterstitial() function
            if (interstitial.isLoaded()) {
                interstitial.show();
            }
        }
    });
}

如果不行,您可以尝试一下,请换一个新线程:

You can try it if not work, please separate to new thread:

 new Thread(new Runnable() {
        public void run() {
        final InterstitialAd interstitial = new InterstitialAd(context);
        interstitial.setAdUnitId(context.getString(id));
        interstitial.loadAd(new AdRequest.Builder().build());
        interstitial.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                // Call displayInterstitial() function
                if (interstitial.isLoaded()) {
                runOnUiThread(new Runnable() {
                public void run() {
                    interstitial.show();
                }
              });                
             }
            }
        });
     }
    }).start();

如果需要,请在单击后-> Admod-> close admod-> apclose:

If your want after click back -> Admod-> close admod -> apclose:

@Override
    public void onBackPressed() {
        final InterstitialAd interstitial = new InterstitialAd(getApplicationContext());
        interstitial.setAdUnitId(getApplicationContext().getString(id));
        interstitial.loadAd(new AdRequest.Builder().build());
        interstitial.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                // Call displayInterstitial() function
                if (interstitial.isLoaded()) {
                    interstitial.show();
                }
            }
            @Override
            public void onAdClosed(){
                finish();
            }
            @Override
            public void onAdFailedToLoad(int errorCode){
                //you can implement continue load or finish 
            }

        });
    }

这篇关于插页式Admob不起作用:未定义AFMA_ReceiveMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆