I'm having problems displaying ads in an Android application. I'm not seeing ads even in test mode.
The layout is taken from admob's instructions, as below:
<?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 } );
in the onCreate
section, to enable test mode. I've also added log messages in the onFailedToReceiveAd
, onFailedToReceiveRefreshedAd
, onReceiveAd
and onReceiveRefreshedAd
functions. 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.
<!-- 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.