cocos2dx版本:2.2.3
admob:google play services
以下是admob插屏广告创建的代码:
public void createInterstitial() {
// Create an ad.
_interstitialAd = new InterstitialAd(_activity);
_interstitialAd.setAdUnitId(AD_UNIT_ID);
// Set the AdListener.
//AdmobInterstitialDelegate delegate = new AdmobInterstitialDelegate();
_interstitialAd.setAdListener(this);
loadInterstitial();
}
public void loadInterstitial() {
// Check the logcat output for your hashed device ID to get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("D2F0DD3A5275B8E6858EA483DD794D55")
.build();
// Load the interstitial ad.
_interstitialAd.loadAd(adRequest);
}
以上代码是在oncreate里调用,但是没有在请求广告成功后立即将插屏广告显示出来,而是在出现某个场景后通过jni调用以下的方法来显示插屏广告。
public void showInterstitial() {
if (
_interstitialAd.isLoaded()) {
_interstitialAd.show();
} else {
Log.d(“Interstitial”, “Interstitial ad was not ready to be shown.”);
}
}
但是,当在执行_interstitialAd.isLoaded()的时候却是出错了。
还请大神指点下!!!
