我是AdMob中的新成員。起初我試圖用不同類型的廣告創建測試應用程序。 我使用真正的ad_unit_id和nexus 4進行測試。廣告請求成功,但由於缺少廣告資源而沒有返回廣告
我用1對佈局XML進行的所有活動:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/empty_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
當我創建橫幅廣告簡單的活動它的做工精細。活動代碼:
public class AdBannerActivity extends Activity {
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ad_empty);
adView = new AdView(this, AdSize.SMART_BANNER, getString(R.string.adUnitId));
adView.setAdListener(this);
LinearLayout layout = (LinearLayout) findViewById(R.id.empty_layout);
layout.addView(adView);
adView.loadAd(new AdRequest());
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
當我嘗試創建一個全屏的廣告活動,我已經錯誤消息:
Ad request successful, but no ad returned due to lack of ad inventory.
活動代碼:
public class AdInterstitialActivity extends Activity implements AdListener {
private InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ad_empty);
interstitial = new InterstitialAd(this, getString(R.string.adUnitId));
interstitial.setAdListener(this);
AdRequest adRequest = new AdRequest();
interstitial.loadAd(adRequest);
}
@Override
public void onReceiveAd(Ad ad) {
if (ad == interstitial) {
interstitial.show();
}
}
@Override
public void onDismissScreen(Ad ad) {
}
@Override
public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
Log.e("AdTest", "Error code: " + error);
}
@Override
public void onLeaveApplication(Ad ad) {
}
@Override
public void onPresentScreen(Ad ad) {
}
}
我在做什麼錯? 如何解決這個問題?
解決方案:爲AdMob帳戶中的插頁式廣告創建新的ad_unit_id。
測試模式的工作很好,但我需要顯示在這個測試程序一個真正的廣告。 – Drafff