2017-02-18 113 views
2

工作,我用這個指南顯示AdMob廣告橫幅在我的應用程序 https://firebase.google.com/docs/admob/android/quick-start 我的問題是,AdMob的橫幅只顯示我的測試設備上這樣 但在真機我沒有看到任何 我在gradle這個文件依賴性是:的AdMob不是真實設備

dependencies { 
compile fileTree(include: ['*.jar'], dir: 'libs') 

compile 'com.android.support:appcompat-v7:25.1.0' 
compile 'com.android.support:design:25.1.0' 
compile 'de.hdodenhof:circleimageview:1.3.0' 
compile 'com.android.support:support-v4:25.1.0' 

compile 'com.google.firebase:firebase-core:10.0.1' 
compile 'com.google.firebase:firebase-ads:10.0.1' 

compile 'com.google.android.gms:play-services:10.0.1' 

compile 'com.android.support:multidex:1.0.1' 
testCompile 'junit:junit:4.12' 
} 
apply plugin: 'com.google.gms.google-services' 

這是我的代碼:

MobileAds.initialize(getContext(), "ca-app-pub-****"); 
AdRequest request = new AdRequest.Builder() 
      .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
      .addTestDevice("4F8D70E24813A8C1CFF9B07A47A4F484") 
      .setRequestAgent("android_studio:ad_template") 
      .build(); 
    mAdView.loadAd(request); 

這是我的xml

<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" 
tools:context="com.saffru.colombo.navigationdrawervideotutorial.MainFragment"> 

<!-- TODO: Update blank fragment layout --> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="@string/l_apos_onomastico_di_oggi" 
    android:id="@+id/textView2" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="100dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="@string/xxx" 
    android:id="@+id/textView3" 
    android:textColor="@color/verde1" 
    android:layout_below="@+id/textView2" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="46dp" /> 

<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="ca-app-pub-****"> 
</com.google.android.gms.ads.AdView> 


</RelativeLayout> 

它不起作用。

這是我的應用的屏幕截圖

我的代碼是

MobileAds.initialize(getContext(), "ca-app-pub-6864438797370510/3840785983"); 

AdView mAdView = (AdView) view.findViewById(R.id.adView); 
AdRequest adRequest = new AdRequest.Builder().build(); 
mAdView.loadAd(adRequest); 

而在我的AdMob帳戶我看到這個

如果我添加.addTestDevice( 「***」) 我logcat的是

02-19 22:07:28.379 2762-2762/com.saffru.colombo.onomastici2 W/System: 
ClassLoader referenced unknown path: 
/data/user/0/com.google.android.gms/app_chimera/m/0000000e/n/armeabi-v7a 
02-19 22:07:28.380 2762-2762/com.saffru.colombo.onomastici2 W/System: 
ClassLoader referenced unknown path: 
/data/user/0/com.google.android.gms/app_chimera/m/0000000e/n/armeabi 
02-19 22:07:28.392 2762-2762/com.saffru.colombo.onomastici2 
I/FirebaseCrashApiImpl: FirebaseCrashApiImpl created by ClassLoader 
p[DexPathList[[zip file" 
/data/data/com.google.android.gms/app_chimera/m/0000000e/ 
DynamiteModulesC_GmsCore_prodmnc_xxhdpi_release.apk"], 
nativeLibraryDirectories[/data/user/0/com.google.android.gms/ 
app_chimera/m/0000000e/n/armeabi-v7a, 
/data/user/0/com.google.android.gms/app_chimera/m/0000000e/n/armeabi, 
/vendor/lib, /system/lib]]] 
02-19 22:07:29.145 2762-2762/com.saffru.colombo.onomastici2 W/System: 
ClassLoader referenced unknown path: 
/data/user/0/com.google.android.gms/app_chimera/m/0000000c/n/armeabi 
02-19 22:07:29.230 2762-2878/com.saffru.colombo.onomastici2 W/System: 
ClassLoader referenced unknown path: 
/data/user/0/com.google.android.gms/app_chimera/m/0000000c/n/armeabi 
02-19 22:07:29.295 2762-2888/com.saffru.colombo.onomastici2 D/OpenGLRenderer: 
Use EGL_SWAP_BEHAVIOR_PRESERVED: true 
+0

份額日誌測試設備..你adUnitId設置可能不正確,嘗試用新的改變它ID? –

+0

我添加了我的logcat –

回答

2

此代碼用於測試admob廣告。我認爲,你遵循了測試廣告教程。

您需要在admob帳戶中創建自己的應用,並將您的廣告單元包含在初始化部分中。

參考鏈接:https://support.google.com/admob/answer/3052638

你的活動代碼。

  MobileAds.initialize(getApplicationContext(), "Your own admob ad-unit"); 

      AdView mAdView = (AdView) findViewById(R.id.adView); 
      AdRequest adRequest = new AdRequest.Builder().build(); 
      mAdView.loadAd(adRequest); 

這四條線就夠了。除此之外,一切都很好。

注意:不要測試您真實的admob廣告單元。如果是這樣,有機會通過谷歌終止您的admob帳戶。

當您在Play商店中發佈應用時,您需要使用真實的廣告單元。

+0

我剛剛創建了一個AdMob帳戶,在我的代碼中,我將該應用ID從AdMob中的應用管理頁面中提取。 –

+0

你的意思是廣告單元?你是否已經改變了這4行代碼?然後,生成已簽名的應用程序,即發佈版本並在Google Play商店中發佈您的應用程序。然後,從那裏下載並檢查。 – Sivakumar

+0

我用這四行更改了代碼,併發布了該應用程序。但是,如何在真實設備上測試它,而不會刪除我的帳戶? –

0

檢查你的日誌,你會發現一個錯誤,你的設備添加爲使用這行代碼從您的設備

`AdSettings.addTestDevice("You will find the Key in your logs");`