目前我正在尝试将广告加载到我的应用程序中。我遵循了指南,这就是我得到的:
的AndroidManifest.xml
<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:largeHeap="true"
android:hardwareAccelerated="true"
android:isGame="true"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
...
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
我已添加AdView
,如此:
<com.google.android.gms.ads.AdView
android:id="@+id/ad_banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/ad_banner_id"
/>
最后加载广告的代码:
adView = (AdView) m.findViewById(R.id.ad_banner);
AdRequest req = new AdRequest.Builder().addTestDevice("my device id").build();
adView.loadAd(req);
现在代码似乎没问题,但是当我运行它时,我得到以下logcat输出:
E/GmsClient﹕ unable to connect to service: com.google.android.gms.ads.service.START
W/Ads﹕ There was a problem getting an ad response. ErrorCode: 0
W/chromium﹕ [WARNING:data_reduction_proxy_settings.cc(328)] SPDY proxy OFF at startup
W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
W/AwContents﹕ onDetachedFromWindow called when already detached. Ignoring
W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
W/Ads﹕ Failed to load ad: 0
然后没有任何内容显示广告的位置。任何人都知道我做错了什么以及为什么以前的错误会出现?感谢。
编辑:我在另一台设备(Nexus 4运行5.1)上尝试过,广告似乎有效。但是他们没有在我的Nexus 5上运行5.0.1答案 0 :(得分:0)
也许您没有最新版本的Google Play服务库。
检查此问题Admob banner and interstitial ads not loading on launcher activity
答案 1 :(得分:0)
这发生在我的手机故障中。一个应用程序正在秘密阻止谷歌播放服务广告服务。我只是禁用它,它很好,所以代码没有错。