Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admob ad not showing up in emulator or phone

Tags:

android

admob

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.

like image 622
Pat Needham Avatar asked Aug 05 '11 03:08

Pat Needham


3 Answers

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());
            }
        });
like image 106
Smugrik Avatar answered Oct 08 '22 18:10

Smugrik


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.

like image 42
Androidcoder Avatar answered Oct 08 '22 18:10

Androidcoder


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());
    }
}
like image 1
vikas kumar Avatar answered Oct 08 '22 18:10

vikas kumar