我正在尝试使用测试广告ID在平板电脑上加载插页式广告。输出广告没有显示,但我收到了“onAdLoaded”的回调。
这是我的代码: -
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ad_activity);
mPublisherInterstitialAd = new PublisherInterstitialAd(this);
mPublisherInterstitialAd.setAdUnitId("/6499/example/interstitial");
mPublisherInterstitialAd.loadAd(newPublisherAdRequest.Builder().build());
mPublisherInterstitialAd.setAdListener(new AdListener(){
@Override
public void onAdLoaded() {
Log.d("AD ","LOADED");
}
@Override
public void onAdFailedToLoad(int i) {
Log.d("AD ","FAILED");
}
});
}
答案 0 :(得分:2)
试试这个
public void inrequestadd() {
mInterstitial = new InterstitialAd(MainActivity.this);
mInterstitial.setAdUnitId("Your ID");
mInterstitial.loadAd(new AdRequest.Builder().build());
mInterstitial.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
}
@Override
public void onAdFailedToLoad(int errorCode) {
super.onAdFailedToLoad(errorCode);
}
@Override
public void onAdLoaded() {
super.onAdLoaded();
if (mInterstitial.isLoaded()) {
mInterstitial.show();
}
}
});
}
答案 1 :(得分:0)
这是我处理这类代码的方式
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initAds();
}
private void initAds() {
MobileAds.initialize(this, "your app id");
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("your ad unit ID");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
// Load the next interstitial.
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
也在清单文件中:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="your app id"/>
接下来,根据您应用的逻辑,您将得到类似的内容:
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
System.out.println("The interstitial wasn't loaded yet. Do some other action");
}