开发者

Admob ad not showing up in emulator or phone

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.


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


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.


guys you also have to call this, for me this was the issue adding so that others can be helped.

mInterstitialAd.loadAd(new AdRequest.Builder().build());

without this it won't work, make sure to call this also.

full sample code

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

public class MainActivity extends Activity {

    private InterstitialAd mInterstitialAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MobileAds.initialize(this,
            "ca-app-pub-3940256099942544~3347511713");
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
    }
}


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜