Jola Kamińska
Jola Kamińska

Reputation: 1

My AdMob ads don't work, and everything seems to be written correctly

My ads do not work and I don't know what is the cause of it. In Activity class, it seems to be everything alright. Same thing is with Gradle. Please help. Maybe something is wrong in AdMob Console.

public class RegisterActivity extends BaseActivity implements View.OnClickListener {

    private static final int RC_SIGN_IN = 9001;

TextView logo;

    private InterstitialAd Memead3;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        findViewById(R.id.button_sign_in).setOnClickListener(this);
        logo = (TextView)findViewById(R.id.textView2);
        Typeface typeface0 = Typeface.createFromAsset(getAssets(), "Baloo-Regular.ttf");
        logo.setTypeface(typeface0);


        Memead3 = new InterstitialAd(this);
        Memead3.setAdUnitId("ca-app-pub-8090166845540486/4438348515");
        Memead3.loadAd(new AdRequest.Builder().build());
        MobileAds.initialize(this, "ca-app-pub-8090166845540486~1312841352");

        if (Memead3.isLoaded()) {
            Memead3.show();
        } else {
            Log.d("TAG", "The interstitial wasn't loaded yet.");
        }

Gradle:

  compile 'com.android.support:appcompat-v7:25.1.0'

    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.firebaseui:firebase-ui-storage:1.1.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.firebaseui:firebase-ui-database:1.1.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.android.gms:play-services-auth:10.0.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'
    compile 'com.android.support:cardview-v7:25.1.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.google.android.gms:play-services-ads:10.0.1'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

Upvotes: 0

Views: 302

Answers (3)

RedBrogdon
RedBrogdon

Reputation: 5351

From your onCreate method:

Memead3.loadAd(new AdRequest.Builder().build());
MobileAds.initialize(this, "ca-app-pub-8090166845540486~1312841352");

if (Memead3.isLoaded()) {
    Memead3.show();
}

With this code, you're calling loadAd, and then a millisecond or two later trying to show the ad with isLoaded and show. That's not enough time for the AdMob SDK to download an ad for you, so isLoaded will always return false.

I would move your attempt to call show out of onCreate and into something else, such as a button handler or when the user leaves the activity.

Also, it doesn't look like you're using test ads in this example. You should always use them when developing your app, since testing with live traffic can cause your account to be suspended. See the Test Ads Guide for details on how to use them.

Upvotes: 1

Nabin Bhandari
Nabin Bhandari

Reputation: 16379

Call MobileAds .initialize(... before trying to load new ads. Also make sure to check logs like "Failed to load ad : 0",etc

Upvotes: 0

kodlan
kodlan

Reputation: 631

Try showing test ads. Load your ads-integrated app and make an ad request. Check the logcat output for a message that looks like this:

I/Ads: Use AdRequest.Builder.addTestDevice("33BE2250B43518CCDA7DE426D04EE232")
to get test ads on this device.
* Copy your test device ID to your clipboard.
* Modify your code to call

Then add it to the AdRequest:

AdRequest request = new AdRequest.Builder()
    .addTestDevice("33BE2250B43518CCDA7DE426D04EE232")
    .build();

Upvotes: 0

Related Questions