简体   繁体   English

Google AdMob载入广告

[英]Google AdMob loading ads

currently I am trying to load ads into my application. 目前,我正在尝试将广告加载到我的应用程序中。 I have followed the guide and this is what i've gotten: 我遵循了指南,这就是我得到的:

AndroidManifest.xml 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>

I've added the AdView like so: 我已经这样添加了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"
    />

And finally the the code to load the ad: 最后是加载广告的代码:

adView = (AdView) m.findViewById(R.id.ad_banner);
AdRequest req = new AdRequest.Builder().addTestDevice("my device id").build();
adView.loadAd(req);

Now the code seems to be alright but when I run it I get the following logcat output: 现在代码似乎还不错,但是当我运行它时,我得到以下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

And then nothing displays where the ad should be. 然后,什么都不会显示广告应在的位置。 Anyone know what I'm doing wrong and why the previous errors are coming up? 有人知道我在做什么错吗,为什么以前的错误会出现? Thanks. 谢谢。

EDIT: I tried it on a different device (Nexus 4 running 5.1) and the ads seemed to work. 编辑:我在另一台设备(运行5.1的Nexus 4)上进行了尝试,并且广告似乎可以正常工作。 But it they don't on my Nexus 5 running 5.0.1 但事实并非如此,它们不在运行5.0.1的Nexus 5上

Maybe you don't have latest version of Google Play Services library. 也许您没有最新版本的Google Play服务库。

Check this similar question Admob banner and interstitial ads not loading on launcher activity 检查这个类似的问题Admob横幅广告和插页式广告不会在启动器活动中加载

This happened to by my phones fault. 这是我的手机故障造成的。 An application was secretly blocking the google play service ad services. 一个应用程序秘密地阻止了Google Play服务的广告服务。 I just had to disable this and it was fine, so nothing wrong with the code. 我只需要禁用它就可以了,所以代码没有错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM