这是我的AdView
<com.google.ads.AdView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId=""
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true"
/>
在Admob网站上,我将“自动刷新”设置为“刷新率:22秒”。
这是LogCat输出:
12-10 11:59:20.757: I/Ads(30363): adRequestUrlHtml: <html><head><script .......
12-10 11:59:22.296: I/Ads(30363): Received ad url: <"url": .....
12-10 11:59:47.085: I/Ads(30363): Refreshing ad.
12-10 11:59:47.390: I/Ads(30363): adRequestUrlHtml: <html><head><script ...........
12-10 11:59:48.339: I/Ads(30363): Received ad url: <"url": .....
12-10 11:59:49.394: I/Ads(30363): onReceiveAd()
12-10 12:00:09.276: I/Ads(30363): Refreshing ad.
12-10 12:00:09.558: I/Ads(30363): adRequestUrlHtml: <html><head><script ......
12-10 12:00:10.046: I/Ads(30363): Received ad url: <"url": ......
12-10 12:00:11.448: I/Ads(30363): onReceiveAd()
12-10 12:00:31.463: I/Ads(30363): Refreshing ad.
12-10 12:00:31.558: I/Ads(30363): adRequestUrlHtml: <html><head><script .......
12-10 12:00:32.085: I/Ads(30363): Received ad url: <"url": ..........
12-10 12:00:33.191: I/Ads(30363): onReceiveAd()
虽然LogCat显示AdMob会刷新广告,但设备上会显示相同的添加(第一次加载的添加)。
Java方面是否需要做任何事情。
更新
Advertise.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res/com.becomputer06.vehicle.diary.free"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId=""
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
/>
</LinearLayout>
AndroidMenifest
<manifest
xmlns:android="http://schemas.android.com/apk/res/android" package="com.becomputer06.vehicle.diary.free"
android:versionCode="2"
android:versionName="1.0.1.FREE">
........
</manifest>
上面列出的代码的结果(编译错误): -
Description Resource Path Location Type
error: No resource identifier found for attribute 'adSize' in package 'com.becomputer06.vehicle.diary.free' advertise.xml /vehicle-diary-free/res/layout line 5 Android AAPT Problem
error: No resource identifier found for attribute 'adUnitId' in package 'com.becomputer06.vehicle.diary.free' advertise.xml /vehicle-diary-free/res/layout line 5 Android AAPT Problem
error: No resource identifier found for attribute 'loadAdOnCreate' in package 'com.becomputer06.vehicle.diary.free' advertise.xml /vehicle-diary-free/res/layout line 5 Android AAPT Problem
R cannot be resolved to a variable
答案 0 :(得分:3)
我在此假设您在XML定义中包含实际的adUnitId。否则你就不会收到广告。
请注意,您处于测试模式。通过指定ads:testDevices="TEST_EMULATOR"
,您要求模拟器向您发送测试广告。当您在测试模式下请求广告时,您每次都会收到相同的广告。尝试删除该参数,或者更好地尝试在设备上进行调试,看看是否得到了不同的结果。
答案 1 :(得分:2)
在Admob网站上,我认为您已通过提供包裹名称来注册您的申请。之后,您需要从网站上获取发布商ID,并将其放在xml中的adUnitId中。
在java代码中:
AdView adview = (AdView)findViewById(R.id.adView);
AdRequest re = new AdRequest();
re.setGender(AdRequest.Gender.FEMALE);
adview.loadAd(re);
在xml中:
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" >
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res/com.xxxx" (com.xxx---> your application package name)
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ads:adSize="BANNER"
android:background="#4876FF"
ads:adUnitId=" "
/>
</LinearLayout>
在Admob网站中,转到设置并将刷新率更改为12秒。 请点击此选项“使用Google广告和Google认证广告网络来提高填充率”。我想这会解决你的问题
在res文件夹---&gt;在“values”下,你需要添加名为attrs.xml的新xml,你需要添加
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.google.ads.AdView">
<attr name="adSize">
<enum name="BANNER" value="1"/>
<enum name="IAB_MRECT" value="2"/>
<enum name="IAB_BANNER" value="3"/>
<enum name="IAB_LEADERBOARD" value="4"/>
</attr>
<attr name="adUnitId" format="string"/>
</declare-styleable>
</resources>
答案 2 :(得分:0)
我遇到了类似的问题。将admob SDK更新到最新版本解决了问题