我的AdMob广告不起作用,似乎所有内容都写得正确

时间:2017-10-01 07:17:39

标签: java android admob

我的广告不起作用,我不知道它的原因是什么。在Activity类中,似乎一切都很好。 Gradle也是如此。请帮忙。也许AdMob控制台出了问题。

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.");
        }

摇篮:

  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'

3 个答案:

答案 0 :(得分:1)

来自onCreate方法:

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

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

使用此代码,您可以调用loadAd,然后在一两秒后尝试使用isLoadedshow来展示广告。 AdMob SDK没有足够的时间为您下载广告,因此isLoaded将始终返回false。

我会尝试从show中调出onCreate,然后转到其他内容,例如按钮处理程序或用户离开活动时。

此外,在此示例中,您似乎并未使用测试广告。您应该在开发应用时始终使用它们,因为使用实时流量进行测试可能会导致您的帐户被暂停。有关如何使用它们的详细信息,请参阅Test Ads Guide

答案 1 :(得分:0)

尝试展示测试广告。 加载广告集成的应用并发出广告请求。 检查logcat输出以查找如下所示的消息:

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

然后将其添加到AdRequest:

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

答案 2 :(得分:0)

在尝试加载新广告之前致电MobileAds .initialize(...。另外,请务必检查"无法加载广告等日志:0"等