Java 加载后立即显示AdMob间隙
在我的Java 加载后立即显示AdMob间隙,java,android,interstitial,Java,Android,Interstitial,在我的onCreate中,我有以下代码: interstitial = new InterstitialAd(this); interstitial.setAdUnitId("ca-app-pub-1852329945819279/4025192744"); // Create ad request. AdRequest adRequest1 = new AdRequest.Builder().build(); // Begin loading you
onCreate
中,我有以下代码:
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-1852329945819279/4025192744");
// Create ad request.
AdRequest adRequest1 = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest1);
其中“interstival”是一个专用interstitalad interstival
然后,我使用以下方法显示间隙:
public void displayInterstitial() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (interstitial.isLoaded()) {
interstitial.show();
}
resetInterstitial();
}
});
}
加载填隙文件后,如何显示填隙文件(调用
displayInterstival()
方法)?感谢您的帮助。请注册在填隙文件加载后通知您的事件:
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-1852329945819279/4025192744");
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
interstitial.show();
}
@Override
public void onAdFailedToLoad(int errorCode) {
// no interstitial available
interstitial = null;
}
});
// Create ad request.
AdRequest adRequest1 = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest1);
如果我没有弄错的话,您不需要检查是否已经加载了interstival(因为只有在加载事件时才会引发该事件),并且它是在UI线程上调用的(因此不需要runOnUiThread)