我在 Android 应用程序中显示广告时遇到问题。即使在测试模式下我也看不到广告。
布局取自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>
主要内容如下:
<?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>
(我的代码中有我的真实发布者 ID)
在我的 Java 代码中,我在 onCreate
部分包含了 AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR } );
以启用测试模式。我还在 onFailedToReceiveAd
、onFailedToReceiveRefreshedAd
、onReceiveAd
和 onReceiveRefreshedAd
函数中添加了日志消息。
但是我仍然看过广告,并且在日志猫中看不到任何输出。
谁能建议我还应该做什么?
最佳答案
您需要权限 ACCESS_NETWORK_STATE 它不见了。
关于android - 在 Android 上显示 Admob 广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4483604/