簡體   English   中英

有一個廣告響應Admob錯誤

[英]There was a getting an ad response Admob Error

我想將舊的GoogleAds SDK一個源代碼更新為新的Google Play Service Library ,但是存在問題。 每次我收到此錯誤:

獲得廣告響應時出現問題。

ErrorCode:0

無法加載廣告:0

這是來自playactivty的代碼:

public String BANNER_AD_UNIT_ID;

AdRequest adRequest;

private void LoadAds()
{
    LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
    this.BANNER_AD_UNIT_ID = getResources().getString(R.string.admob_id);
    // Create the adView
    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(BANNER_AD_UNIT_ID);

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .build();
//  AdRequest.setTesting(true);
    adView.loadAd(adRequest);   
}

並從layout.xml

    </RelativeLayout>

  <com.google.android.gms.ads.AdView

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    ads:adSize="BANNER"
    ads:adUnitId="@string/admob_id">
</com.google.android.gms.ads.AdView>
<LinearLayout
        android:orientation="horizontal"

        android:id="@+id/adView" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

</LinearLayout>

那里我做錯了什么? 找不到問題,相信我,我讀了所有關於那個錯誤的SOF帖子:)

非常感謝你!

編輯:

原始代碼:

PlayActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play);
    LoadConfigParams();
    LoadSharedPreferences();
    LoadResources();
    LoadListeners();        
    LoadStage(mCurStage);
    LoadAds();


}

    private void LoadAds()
{
    LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayoutAdmob);

    // Create the adView
    AdView adView = new AdView(this, AdSize.SMART_BANNER, getResources().getString(R.string.admob_id));

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    request.setTesting(true);
    adView.loadAd(request); 
}

activity_play.xml (只有最后一個LinearLayout代碼,上面是RelativeLayout)。

    <LinearLayout
        android:id="@+id/linearLayoutAdmob" android:layout_width="fill_parent"
        android:layout_height="wrap_content"></LinearLayout>

有兩種方法可以通過javaxml創建Admob添加,最簡單的方法 - (即使兩者都很簡單)是xml 。如果你使用SMART_BANNER你會得到不同大小的添加,如果大小不合適/匹配您的RelativeLayoutLinearLayout留下的剩余屏幕空間,您的添加將不會顯示。 所以我會假設你已經照顧好了

<LinearLayout
    android:id="@+id/linearLayoutAdmob" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

     <com.google.android.gms.ads.AdView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      ads:adSize="SMART_BANNER"
      android:id="@+id/myaddview"
      ads:adUnitId="@string/admob_id">
</LinearLayout>

然后在你的loadAds()

AdView adView = findViewById(R.id.myaddview); //add the cast
 AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);   

多數民眾贊成你需要檢查這一點以了解要導入的內容並仔細檢查你的權限

MobileAds.initialize(本);

適合我

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM