2014-02-10 77 views
1

我遇到了AdMob和Google Play服務的問題,這讓我瘋狂了好幾天。感覺實際上不可能完成這項工作。這個實現有什麼問題?AdMob和Google Play服務庫中的廣告未在設備上顯示

layout.xml(下面的代碼變爲在佈局的底部):

xmlns:ads="http://schemas.android.com/apk/res-auto" 
... 
    <LinearLayout 
     android:id="@+id/layoutAd" 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_marginTop="5dp" 
     android:layout_weight="3" 
     android:orientation="vertical" > 

     <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      ads:adSize="BANNER" 
      ads:adUnitId="@string/ad_unit_id" /> 

    </LinearLayout> 

MainActivity.java:

import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdView; 
import com.google.android.gms.ads.AdSize; 

... 
adView = (AdView)this.findViewById(R.id.adView); 
AdRequest request = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR). 
     addTestDevice("9234EBAE83E894E6271DEBE7B380782E").build();    
adView.loadAd(request); 

的AndroidManifest.xml:

<meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
    ... 
      <activity android:name="com.google.android.gms.ads.AdActivity" 
       android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

logcat的:

Use AdRequest.Builder.addTestDevice("9234EBAE83E894E6271DEBE7B380782E") to get test ads on this device. 

GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. 

SQLiteLog: (14) cannot open file at line 30241 of [00bb9c9ce4] 

SQLiteLog: (14) os_unix.c:30241: (2) open(/NotificationPermissions.db) - 

廣告永遠不會顯示,但如果我在模擬器上運行它,它會。

我什麼東錯了?

+0

這是同樣的問題:http://stackoverflow.com/questions/21382029/admob-test-ads-shows-only-在英語設備....也許,它可以幫助! –

回答

-3

嘗試使用:

import com.google.android.gms.ads.*; 

相反的:

import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdView; 
import com.google.android.gms.ads.AdSize; 

這種固定的一些問題對我來說。

0

我的建議註釋的代碼

addTestDevice( 「9234EBAE83E894E6271DEBE7B380782E」)建立();

,並連接您的手機,請確保計算機檢測到您的手機 並運行該項目,設備應該出現在選擇設備上運行 單擊確定

希望這helpe

最後一個建議,如果你使用Eclipse,轉到頂部菜單項目點擊 很多時候這清理工作區中的垃圾數據