【发布时间】:2015-04-22 00:44:54
【问题描述】:
目前我正在尝试将广告加载到我的应用程序中。我遵循了指南,这就是我得到的:
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 上
【问题讨论】: