Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
611 views
in Technique[技术] by (71.8m points)

android - Interstitial Admob doesn't work : AFMA_ReceiveMessage is not defined

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)

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 ?

Thanks for helping me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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 
            }

        });
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...