Admob ad not showing up in emulator or phone

风格不统一 提交于 2019-12-18 06:17:04

问题


I am trying to place Admob ads in my app, and I followed all the instructions but it's not working.

AdView adView = new AdView(this, AdSize.BANNER, "My_ID");
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    flashCardPage.addView(adView, lp);
    adView.loadAd(new AdRequest());

My manifest file contains the activty tag and the two permissions, just like the tutorial, but the banner does not show up on the screen. Interestingly, when I took out all the Admob stuff from my manifest file and ran the application, a banner shows up on the bottom of my screen saying I need to allow internet and network-state access. Does anyone know what I'm doing wrong? I know there are a lot of questions on this topic already, but none of them have helped. I tried changing my Admob account to test mode and adding the emulator as a test project, but that didn't work.

Should I try using another advertising method? It's been about a week and Admob ads still aren't showing up.

When I ran the app on my phone today (August 10), I got a forced close, so I'm thinking that if Admob causes that, even only 1%-5% of the time, I won't use it.


回答1:


Ii might be the case that AdMob simply doesn't have ads to serve, you can try adding that piece of code after your adView declaration to see what it tells on fail to receive ad.

 // Set AdListener
        adView.setAdListener(new AdListener() {
            @Override
            public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
                System.err.println("Ad failed: " + ad.toString() + error.toString());    
            }

            @Override
            public void onReceiveAd(Ad ad) {
                System.out.println("Ad received: " + ad.toString());
            }
        });



回答2:


Did you go back to your admob account to register your specific app for ads and get a new longer publisher number with the 'ca-app-pub-' preface instead of the 'pub-' preface?

Nowhere in the "banner ads 1" instructions on the Google Admob "Google Mobile Ads SDK" development site does it mention having to go back to your admob account to do this.

This stupid mistake held me up for days.




回答3:


Check your log cat output for any debug messages from admob. It should say when a ad is requested or not loaded. Honestly, when I first started mine would hardly ever show an ad. Eventually they just started to show. No real explanation.




回答4:


I would try just adding the ad xml first. Also, make sure that you are set up to receive ads via admob.

See Defining a com.google.ads.AdView.

Via admob, login, and go to Sites & Apps (here you can see if ads are really being sent to your app or not), scroll down to your app. When you mouse over you app, you will see a button that says "Manage Settings". Click it and then go to App Settings. This will help you control how the ad appears and the refresh rate, etc.




回答5:


This problem is solved by uninstalling the app manually and reinstalling again without making any changes!!



来源:https://stackoverflow.com/questions/6951106/admob-ad-not-showing-up-in-emulator-or-phone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!