我想运行我从 这里获得的谷歌开发者示例应用程序
- 我已经在 admobs.com 上注册了我的广告单元 ID,其格式为:ca-app-pub-7.../... 在 main.xml 中,我随后将 AD_UNIT_ID_GOES_HERE 替换为这个新的广告单元 ID。
然后我在 main.xml TEST_DEVICE_ID_GOES_HERE 中替换了我从 logcat 获得的设备 ID:
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>
我正在使用最新版本的 GoogleAdMobAdsSdkAndroid-6.4.1。感谢您的任何建议。
编辑:我已经在模拟器和其他手机上尝试过我的应用程序,没有问题。广告横幅显示良好。没有出现横幅的手机是三星 I5801 和 android 2.3.7。它最初不是我的手机,它可能是 root 手机,可能是什么原因,但我不确定(我在论坛上找到了它)。