一个月以来,我在Admob上创建了一个帐户,并且从两天前开始添加付款方式。 成功显示广告的测试设备。但其他设备未显示任何错误代码为3的东西
广告:广告无法加载:3
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
private AdView adView;
private Button onePlayer, twoPlayer, exit;
private InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, getString(R.string.app_id));
MobileAds.initialize(this, initializationStatus -> {
});
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.instruction));
mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("my-device-id").build());
mInterstitialAd.setAdListener(InterstitialListener);
adView = findViewById(R.id.adView);
adView.loadAd(new AdRequest.Builder().addTestDevice("my-device-id").build());
adView.setAdListener(adListener);
}
}
然后我为InterstitialAd创建了一个监听器
private AdListener InterstitialListener = new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
mInterstitialAd.show();
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
Toast.makeText(getApplicationContext(), "errorCode " + errorCode + "", Toast.LENGTH_LONG).show();
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when the interstitial ad is closed.
}
};
这是横幅xml:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner">
</com.google.android.gms.ads.AdView>
注意:该应用尚未上传到商店!
我该如何解决此问题?
答案 0 :(得分:0)
您的代码似乎正常。 您是否正在使用此测试单元ID作为横幅?
ca-app-pub-3940256099942544 / 6300978111
或者您正在使用AdMob帐户中的那个?
答案 1 :(得分:0)
此答案将来可能会对某人有所帮助。我有同样的问题。广告在测试设备上运行良好。但是在实际设备中,它没有显示任何广告。
我将自己的作品发布到了Google Play并下载了。在从google play下载的应用中,广告展示良好。 我没有对代码进行任何更改
我不确定为什么会发生这种情况,这有点像黑匣子。
堆栈溢出中的一些答案表明无需发布用于展示广告的应用。但这不是我的情况。