Android 广告没有出现
我想运行一个谷歌开发者示例应用程序,我从 我已在admobs.com注册,我的广告单元ID的格式为:ca-app-pub-7…/。。。在main.xml中,我在这里替换了这个新的广告单元ID的广告单元ID。 然后,我在main.xml TEST_DEVICE_ID_GOES_中替换了我从logcat获得的设备ID:Android 广告没有出现,android,admob,Android,Admob,我想运行一个谷歌开发者示例应用程序,我从 我已在admobs.com注册,我的广告单元ID的格式为:ca-app-pub-7…/。。。在main.xml中,我在这里替换了这个新的广告单元ID的广告单元ID。 然后,我在main.xml TEST_DEVICE_ID_GOES_中替换了我从logcat获得的设备ID: 09-07 19:49:30.881: I/Ads(5735): To get test ads on this device, call adRequest.addTestDev
09-07 19:49:30.881: I/Ads(5735): To get test ads on this device, call adRequest.addTestDevice("EFEA76C9D061FDD37B8ABF6EB712A991");
此外,在BannerSample.java中,我将代码添加到onCreate中:
package com.google.example.ads.xml;
import com.google.ads.AdRequest;
import android.app.Activity;
import android.os.Bundle;
/**
* A simple {@link Activity} which embeds an AdView in its layout XML.
*/
public class BannerSample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// This example requires no additional code since the optional
// "loadAdOnCreate=true" XML attribute was used. If "loadAdOnCreate" were
// not specified, the ad would have to be loaded by creating an AdRequest
// and using Activity.findViewById() to get the AdView.
//
// The "loadAdOnCreate" XML attribute makes it simpler to get ads since no
// code is required, but it also limits the developer's control over the ad
// request since a generic AdRequest is used.
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
request.addTestDevice("EFEA76C9D061FDD37B8ABF6EB712A991");
}
}
我等了几分钟,应用程序正在运行,但广告横幅并没有出现
日志:
09-07 20:32:01.037: W/webcore(5945): Can't get the viewWidth after the first layout
09-07 20:33:00.306: I/Ads(5945): AdLoader timed out after 60000ms while getting the URL.
09-07 20:33:00.310: D/webviewglue(5945): nativeDestroy view: 0x1cb198
09-07 20:33:00.322: I/Ads(5945): onFailedToReceiveAd(A network error occurred.)
我也尝试过将代码添加到清单中。我在stackoverflow上看到过,但没有成功
<meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="pub-7..."
>
</meta-data>
我使用的是最新版本的GoogleedMobadSDKDK Android-6.4.1。谢谢你的建议
编辑:
我在emulator和其他手机上试用了我的应用程序,没有问题。广告横幅显示良好。没有出现横幅的手机是搭载安卓2.3.7的三星I5801。它本来不是我的手机,可能是根手机,原因可能是什么,但我不确定我是否在论坛上找到了它。试试看
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
adView.loadAd(adRequest);
}
在主布局中添加
xmlns:ads=http://schemas.android.com/apk/lib/com.google.ads
及
希望有帮助:您可以在字符串中定义您的admob id,以及所有测试设备,以便于访问
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/myAdView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
googleads:adSize="SMART_BANNER"
googleads:adUnitId="@string/admob_id"
googleads:testDevices="@string/ADS_TEST_DEVICES" />
快乐编码 您可能忘记在Android maifest文件上添加权限。好像是这样 互联网与 在靠近清单标签的Android清单中需要访问\u网络\u状态权限。消息:获取广告响应时出现问题。错误代码:1表示ad单元ID无效
public static final int ERROR_CODE_INVALID_REQUEST
The ad request was invalid; for instance, the ad unit ID was incorrect.
Constant Value: 1 (0x00000001)
解决方案是更改ad单元ID
package com.google.example.ads.xml;
import com.google.ads.AdRequest;
import android.app.Activity;
import android.os.Bundle;
/**
* A simple {@link Activity} which embeds an AdView in its layout XML.
*/
public class BannerSample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdView myAdView = (AdView) this.findViewById(R.id.myAdView);
AdRequest request = new AdRequest();
myAdView.loadAd(adRequest);
}
}
public static final int ERROR_CODE_INVALID_REQUEST
The ad request was invalid; for instance, the ad unit ID was incorrect.
Constant Value: 1 (0x00000001)