简体   繁体   English

在Android上显示Admob广告

[英]Displaying Admob Ads on Android

I'm having problems displaying ads in an Android application. 我在Android应用程序中显示广告时遇到问题。 I'm not seeing ads even in test mode. 即使在测试模式下也看不到广告。

The layout is taken from admob's instructions, as below: 布局取材于admob的说明,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/lgf.fourinarow"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

  <com.admob.android.ads.AdView 
      android:id="@+id/ad" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      app:backgroundColor="#000000"
      app:primaryTextColor="#FFFFFF"
      app:secondaryTextColor="#CCCCCC"
      app:keywords="Android Game"
  />
</LinearLayout>

The mainfest is below: 最主要的内容如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="lgf.fourinarow"
    android:versionCode="1"
    android:versionName="1.0">
  <!-- Requires Android 2.1 or above -->
  <uses-sdk android:minSdkVersion="7" />
  <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".LGFFourInARow">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <!-- Track Market installs --> 
    <receiver android:name="com.admob.android.ads.analytics.Inst allReceiver" android:exported="true">
      <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER " />
      </intent-filter>
    </receiver>

    <!-- The application's publisher ID assigned by AdMob -->
    <meta-data android:value="xxxxxxxxxxxxxx" android:name="ADMOB_PUBLISHER_ID"/>
  </application>
  <!-- AdMob SDK permissions -->
  <uses-permission android:name="android.permission.INTERNET" />
</manifest> 

(I have my real publisher id in my code) In my Java code, I have included AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR } ); (我的代码中包含真正的发布者ID)在Java代码中,我包含了AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR } ); in the onCreate section, to enable test mode. onCreate部分中,以启用测试模式。 I've also added log messages in the onFailedToReceiveAd , onFailedToReceiveRefreshedAd , onReceiveAd and onReceiveRefreshedAd functions. 我还在onFailedToReceiveAdonFailedToReceiveRefreshedAdonReceiveAdonReceiveRefreshedAd函数中添加了日志消息。 However I have still ever seen and ad, and can't see any output in the log cat. 但是我仍然看过广告,并且在日志猫中看不到任何输出。 Can anyone suggest what else I should be doing? 有人可以建议我还要做什么吗?

您需要其权限ACCESS_NETWORK_STATE。

Try putting Internet permission before the <application> tag in the manifest. 尝试将Internet权限放在清单中<application>标记之前。

    <!-- AdMob SDK permissions -->
    <uses-permission android:name="android.permission.INTERNET" />
  </application>
</manifest>

Also, have you verified that you can load a web page in the browser? 另外,您是否已验证可以在浏览器中加载网页? Sometimes the emulator has DNS problems. 有时仿真器存在DNS问题。

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

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