我尝试按照Google ADMOB广告添加代码但不起作用。然后我开始使用GITHUB示例添加插页式广告。我的项目没有任何错误。 Eclipse没有代替广告。请看看我的代码并告诉我哪里出错了。我会在必要时突出显示内容。 BANNER ADS正在工作!!!!
public class AppGame extends Activity {
AdView adView;
/** The log tag. */
private static final String LOG_TAG = "InterstitialSample";
/** Your ad unit id. Replace with your actual ad unit id. */
private static final String AD_UNIT_ID1 = "INSERT AD ID HERE";
/** The interstitial ad. */
private InterstitialAd interstitialAd;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(AD_UNIT_ID1);
// Set the AdListener.
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.d(LOG_TAG, "onAdLoaded");
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Change the button text and disable the button.
}
});
}
/** Called when the Load Interstitial button is clicked. */
public void loadInterstitial(View unusedView) {
// Disable the show button until the new ad is loaded.
// 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("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Load the interstitial ad.
interstitialAd.loadAd(adRequest);
}
/** Called when the Show Interstitial button is clicked. */
public void showInterstitial(View unusedView) {
// Disable the show button until another interstitial is loaded.
if (interstitialAd.isLoaded()) {
interstitialAd.show();
} else {
Log.d(LOG_TAG, "Interstitial ad was not ready to be shown.");
}
}
/** Gets a string error reason from an error code. */
private String getErrorReason(int errorCode) {
String errorReason = "";
switch(errorCode) {
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
errorReason = "Internal error";
break;
case AdRequest.ERROR_CODE_INVALID_REQUEST:
errorReason = "Invalid request";
break;
case AdRequest.ERROR_CODE_NETWORK_ERROR:
errorReason = "Network Error";
break;
case AdRequest.ERROR_CODE_NO_FILL:
errorReason = "No fill";
break;
}
return errorReason;
}
}
答案 0 :(得分:1)
设置好adunit后调用loadInterstitial(v)
:
interstitialAd.setAdUnitId(AD_UNIT_ID1);
loadInterstitial(v);
在您希望展示广告的时间/地点致电showInterstitial(v)
:
答案 1 :(得分:0)
您忘记致电loadInterstitial
功能,以便加载插页式广告。
在onCreate
功能中,调用loadInterstitial
功能。然后像这样添加监听器:
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.d(LOG_TAG, "onAdLoaded");
interstitialAd.show();
}
或将布尔值设置为true并在应用程序的自然断点处,检查布尔值是否为真,然后显示广告。
答案 2 :(得分:0)
我的测试设备中存在同样的问题。我搜索了这么多天。但我没有得到任何解决方案。
最后我尝试删除代码
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
我得到了成功的结果。
所以在测试的最后一步尝试这样。
答案 3 :(得分:0)
onCreate添加以下行
mInterstitialAd = new InterstitialAd(this);
// set the ad unit ID
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
}
@Override
public void onAdLoaded() {
// Ads loaded, stop requesting
mInterstitialAd.show();
//update time start
timeStart = new Date().getTime();
}
});
onResume check time显示Intertitial广告和发送请求广告:
if(new Date().getTime()-timeStart>=timeShowAds) {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("36E0B62FE34536712ED1BEBD85467085")
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest);
}