gpt4 book ai didi

android - 广告未出现

转载 作者:行者123 更新时间:2023-11-29 17:56:57 25 4
gpt4 key购买 nike

我想运行一个谷歌开发者示例应用程序,我从 here

  1. 我已在 admobs.com 上注册,我的广告单元 ID 的格式为:ca-app-pub-7.../... 在 main.xml 中,我已将 AD_UNIT_ID_GOES_HERE 替换为这个新广告单元 ID。
  2. 然后我在 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.)

我已经尝试过将代码添加到 list 中。(我已经在 stackoverflow 上看到了它,但没有成功)。

    <meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="pub-7..."
>
</meta-data>

我使用的是最新版本的 GoogleAdMobAdsSdkAndroid-6.4.1。感谢您的任何建议。

编辑:我已经在模拟器和其他手机上尝试过我的应用程序,没有问题。广告横幅显示正常。未出现横幅的手机是 Samsung I5801 with android 2.3.7。这不是我原来的手机,它可能是根电话可能是什么原因,但我不确定(我在论坛上找到它)。

最佳答案

尝试

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"和

<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="YOUR_KEY"
ads:refreshInterval="32" />

希望对您有所帮助:)

关于android - 广告未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18676607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com