示例:我想要的当您打开应用程序时,广告会在5秒内出现,如果不同,将取消展览并且应用程序将继续执行主要活动段落。我使用的代码是:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitialAd = new InterstitialAd(Main.this);
interstitialAd.setAdUnitId(getString(R.string.adMobInter));
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(getString(R.string.adMob_test))
.build();
interstitialAd.loadAd(adRequest);
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
displayInterstitial();
}
@Override
public void onAdFailedToLoad(int errorCode) {
onMain();
}
@Override
public void onAdClosed() {
onMain();
}
});
}
public void displayInterstitial() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
public void onMain() {
setContentView(R.layout.main);
}