gpt4 book ai didi

Android AdMob addTestDevice 没有在 logcat 中获取 deviceID

转载 作者:行者123 更新时间:2023-11-30 02:38:22 24 4
gpt4 key购买 nike

我正在尝试使用 Google Play 服务实现 AdMob。到目前为止,我已经显示了默认的测试横幅,但我想尝试一些测试广告。

我读到模拟器 (AVD) 必须将 Google API 16 或 17 作为目标才能测试 AdMob,但是当我创建一个以此为目标的设备时,模拟器无法加载(我把它留了好久20 分钟还没有加载 :( 我只看到闪烁的 android 标志

这是我的 AVD 设备

enter image description here

这是我的 AdFragment 类,其中包含与广告相关的所有代码

public class AdFragment extends Fragment 
{

private AdView mAdView;

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment_ad, container, false);

}

@Override
public void onActivityCreated(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
mAdView = (AdView)getView().findViewById(R.id.adView);

AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();


// Start loading the ad in the background.
mAdView.loadAd(adRequest);

}

/** Called when leaving the activity */
@Override
public void onPause()
{
if (mAdView != null)
{
mAdView.pause();
}

super.onPause();
}

/** Called when returning to the activity */
@Override
public void onResume()
{
super.onResume();
if (mAdView != null)
{
mAdView.resume();
}
}

/** Called before the activity is destroyed */
@Override
public void onDestroy() {
if (mAdView != null)
{
mAdView.destroy();
}
super.onDestroy();
}



}

现在我不确定是我的代码没有生成设备 ID 还是我创建的 AVD 设备有问题。我看的教程都是这样的

.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("2EAB96D84FE62876379A9C030AA6A0AC")

现在我不知道最后一行是 LogCat 给出的代码还是我必须输入的代码。我注意到 developer.google 网站有不同的代码所以我想我不需要包含在我的代码中,因为我还没有得到它。

请帮忙。谢谢。

更新 1我在我的主要 Activity 中的 On Resume 中添加了这段代码

@Override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
int isAvaiable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(isAvaiable == ConnectionResult.SUCCESS)
{
Log.d("TEST", "GPS IS OK");
}
else if(isAvaiable == ConnectionResult.SERVICE_MISSING || isAvaiable == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED || isAvaiable == ConnectionResult.SERVICE_DISABLED)
{
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvaiable, this, 1);
dialog.show();
}

}

最佳答案

用于测试横幅的 API 应为 17 或更高版本。你在这里有一个很好的答案来解释它。 GPS in emulator .

对于与启动模拟器相关的问题,我唯一能给你的建议是尝试VM Acceleration并使用较小的屏幕。您可以尝试其他模拟器,例如 x86Emulator并下载最后一个ISO versions 4.4 .在我的例子中,默认的 android 模拟器需要 10-12 分钟才能在 ldpi 中响应,而另一个在 hdpi 中只有 2 分钟。

关于 addTestDevice,我认为 AdRequest.DEVICE_ID_EMULATOR 就足够了,但如果您在 logcat 中看到设备 ID 的 MD5,则添加此哈希值。

最后但同样重要的是,记得在开始时检查是否安装了 GPS,DOCS 上有说明。

To verify the Google Play services version, call isGooglePlayServicesAvailable(). If the result code is SUCCESS, then the Google Play services APK is up-to-date and you can continue to make a connection. If, however, the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then the user needs to install an update.

这样你就可以避免错误。

关于Android AdMob addTestDevice 没有在 logcat 中获取 deviceID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26170462/

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