【问题标题】:Google AdMob loading adsGoogle AdMob 加载广告
【发布时间】: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 上

【问题讨论】:

    标签: java android admob ads


    【解决方案1】:

    也许您没有最新版本的 Google Play 服务库。

    检查这个类似的问题Admob banner and interstitial ads not loading on launcher activity

    【讨论】:

    • 我正在使用 google play services 7.0.0。我的依赖项下有以下内容:compile 'com.google.android.gms:play-services:7.0.0'
    【解决方案2】:

    这是我的手机故障造成的。一个应用程序正在秘密阻止 google play service 的广告服务。我只需要禁用它就可以了,所以代码没有问题。

    【讨论】:

    • 我遇到了同样的问题,请您详细说明您是如何解决的?
    • 我已经root了我的手机并安装了一个名为lucky patcher的应用程序。它允许您阻止谷歌广告。尽管我不知道,但我选择了该选项
    • 感谢您的重播。顺便说一句,我用不同的方法解决了我的类似问题,我有自定义 ROM,它集成了预广告拦截器。显然我的手机也已root,所以转到文件管理器,然后转到根文件夹(设备文件夹),然后转到/etc/文件夹,在那里我找到了一个名为Hosts的文件,该文件包含广告代理商的所有URL,并且这些URL被循环返回 127.0.0.1 IP。只需删除该文件并重新启动我的手机。现在我的广告可以正常工作了。
    猜你喜欢
    • 1970-01-01
    • 2016-11-17
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多