[英]Google AdMob loading ads
目前,我正在尝试将广告加载到我的应用程序中。 我遵循了指南,这就是我得到的:
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
然后,什么都不会显示广告应在的位置。 有人知道我在做什么错吗,为什么以前的错误会出现? 谢谢。
编辑:我在另一台设备(运行5.1的Nexus 4)上进行了尝试,并且广告似乎可以正常工作。 但事实并非如此,它们不在运行5.0.1的Nexus 5上
也许您没有最新版本的Google Play服务库。
检查这个类似的问题Admob横幅广告和插页式广告不会在启动器活动中加载
这是我的手机故障造成的。 一个应用程序秘密地阻止了Google Play服务的广告服务。 我只需要禁用它就可以了,所以代码没有错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.