我正在嘗試將一些Admob廣告添加到我的應用程序中。到目前爲止,我已將以下代碼放入onCreate
方法中。Android AdMob超時
long previousAdShown = this.prefs.getLong("last_ad_shown", 0);
long now = new Date().getTime();
if (Constants.ADMOB_ENABLE && (previousAdShown < now - Constants.ADMOB_INTERVAL))
{
Log.e("ADMOB", "Load ADMOB");
// Load ad view
this.adView = new InterstitialAd(this);
this.adView.setAdUnitId(Constants.ADMOB_ID);
AdRequest.Builder adRequest = new AdRequest.Builder();
adRequest.addTestDevice("31090DB31C8059FC6EF0FDA2XXXXXXXX");
this.adView.loadAd(adRequest.build());
// Update timer
this.prefs.edit().putLong("last_ad_shown", now).commit();
}
這應該是預加載廣告。
然後,在我的菜單我有類似的東西:
this.menu_me_feed_layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view)
{
if (adView != null && adView.isLoaded())
{
adView.show();
adView.setAdListener(new AdListener() {
@Override
public void onAdClosed()
{
Intent intent = new Intent(LeftMenu.this.activity, UserFeedActivity.class);
intent.putExtra("isForUser", false);
LeftMenu.this.activity.startActivity(intent);
LeftMenu.this.activity.finish();
}
});
}
else
{
Intent intent = new Intent(LeftMenu.this.activity, UserFeedActivity.class);
intent.putExtra("isForUser", false);
LeftMenu.this.activity.startActivity(intent);
LeftMenu.this.activity.finish();
}
}
});
如果以前裝入這基本上顯示廣告。
我有兩個錯誤:
03-26 20:44:37.437: E/GooglePlayServicesUtil(28151): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
其中,根據AdMob聯播文檔,不是阻止錯誤。03-26 20:44:59.242: W/Ads(28151): Timed out waiting for ad response. 03-26 20:44:59.252: W/dalvikvm(28151): disableGcForExternalAlloc: false 03-26 20:44:59.257: W/Ads(28151): Failed to load ad: 2
我不明白爲什麼我得到了那些錯誤,我AdUnitId
是正確的。
有什麼想法?
感謝您的幫助。
感謝您的回答。事實上,我的聯繫速度太慢,無法及時檢索廣告。今天早上再試,解決了我的問題。 – Manitoba