2016-01-02 56 views
0

我在展示AdMob橫幅時遇到了一些問題。我得到錯誤1,這意味着ERROR_CODE_INVALID_REQUEST。當我更改setAdUnitId並使用UnitId進行測試時,它可以正常工作。但是當我使用從AdMob提供的我的UnitId時,出現錯誤。AdMob橫幅廣告請求失敗,代碼爲ERROR_CODE_INVALID_REQUEST 1

這是佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      xmlns:ads="http://schemas.android.com/apk/res-auto" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#262626" 
      tools:context="com.elis91.elis.contatti.Contatti"> 

<LinearLayout 
    android:id="@+id/linearLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#1e88e6" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/textView5MSGnonLetti" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="You have 0 new messagges" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#cdfff9f9" 
     android:textSize="20dp"/> 
</LinearLayout> 

<ListView 
    android:id="@+id/listView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_below="@+id/linearLayout" 
    android:layout_above="@+id/relativeLayout3"/> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="52dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:id="@+id/relativeLayout3" 
    android:gravity="bottom"> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@+id/banner_ad_unit_id"> 
    </com.google.android.gms.ads.AdView> 

</RelativeLayout> 

這是Android:

private void setupGoogleAds(){ 
    AdView mAdView = (AdView) findViewById(R.id.adView); 
    AdRequest adRequest = new AdRequest.Builder() 
      //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
      .build(); 

    mAdView.loadAd(adRequest); 
    mAdView.setAdListener(new AdListener() { 
     @Override 
     public void onAdOpened() { 
      Log.d("esx", "onAdOpened"); 
      // Save app state before going to the ad overlay. 
     } 

     @Override 
     public void onAdLoaded() { 
      Log.d("esx", "onAdLoaded"); 
      // Save app state before going to the ad overlay. 
     } 

     @Override 
     public void onAdFailedToLoad(int errorCode) { 

      Log.d("esx", "onAdFailedToLoad: " + errorCode+"--"+AdRequest.ERROR_CODE_NO_FILL+"-"+AdRequest.ERROR_CODE_NETWORK_ERROR+"-"+AdRequest.ERROR_CODE_INVALID_REQUEST+"-"+AdRequest.ERROR_CODE_INTERNAL_ERROR+"-"); 
      // Save app state before going to the ad overlay. 
     } 

     @Override 
     public void onAdClosed() { 
      Log.d("esx", "onAdClosed"); 
      // Save app state before going to the ad overlay. 
     } 

     @Override 
     public void onAdLeftApplication() { 
      Log.d("esx", "onAdLeftApplication"); 
      // Save app state before going to the ad overlay. 
     } 
    }); 
} 

回答

2

ERROR_CODE_INVALID_REQUEST指:

廣告請求WA無效;例如,廣告單元ID是 不正確。

Source

檢查如果傳遞正確的廣告單元ID。

我檢查了你的代碼,並認爲問題在這裏。

你寫

ads:adUnitId="@+id/banner_ad_unit_id" 

您一定意味寫

ads:adUnitId="@string/banner_ad_unit_id" 

假設你已經存儲在廣告單元ID在你的字符串資源。如果不是在你的字符串資源把它直接如下:

ads:adUnitId="XXXXXXXXXXXXXXXX" // Replace XXXXXXXXXXXXXXXX with your ad unit id. 
+0

THX的人,問題是@ + ID /,我changet爲@ string /和工作 – Ares91

+0

OMG香港專業教育學院的「CA-前有空格...「從複製,謝謝 – urSus