gpt4 book ai didi

android - 使用 Google Play 服务的 AdMob - 测试广告 - 广告服务器未填充

转载 作者:可可西里 更新时间:2023-11-01 19:08:30 25 4
gpt4 key购买 nike

早上好

我的问题是我的应用中根本没有显示广告,无论是否处于测试模式。我将让这个问题特定于测试模式,一旦我开始工作,我就会担心实时广告。

开发信息

我正在使用 Eclipse 进行开发。

我在我的 Android 应用程序中使用 Google Play 服务和 Admob 设置了广告,如 Google 提供的在线文档中所述。

我使用 addTestDevice("xxxxxxxxxxxxxxxx") 添加了我的设备 ID,并多次检查了哈希设备 ID 以确保它是正确的。

我正在使用真实设备进行测试。 HTC Sensation 与 Android 4.1.2。设备上安装的其他应用的广告运行良好。

问题(请参阅下面的日志信息)

当我在我的设备上运行该应用程序时,根本没有显示任何广告。即使我已将我的设备添加为测试设备,也会发生这种情况。

我到处搜索,发现了很多类似的问题,但我还没有找到这个具体问题的答案。

我试过很多东西:

  • 在模拟器中运行(这里的问题是在我的旧笔记本电脑上运行较新版本的 Android)。同样的问题。
  • 从头开始重写整个广告代码。
  • 重新导入 Google Play 服务。
  • 正在重新安装 eclipse - 现在使用最新的 Android 开发者工具。
  • 下载 Google Play 服务并再次导入项目。
  • 多次清理我的项目。
  • 谷歌搜索、谷歌搜索和更多谷歌搜索。

我根本无法深入了解这个问题。我将非常感谢任何能在这里帮助我的人。我有一种感觉,我可能遗漏了导致我出现这些问题的一些非常小但很重要的东西。

我担心的行已放在下面的过滤日志中(“广告服务器未填充”)。在完整的日志中,还有一行“未找到 google play 服务资源”,但经过一些研究,这似乎不是我的问题的原因,看起来我们可以忽略。

无论如何,我想这就是我所拥有的所有信息 - 提前感谢任何为我调查此事的人。

过滤日志

当按“log:ads”过滤时,LogCat 输出以下内容:

03-15 09:51:46.549: I/Ads(12405): Use AdRequest.Builder.addTestDevice("A24031FACA2D8B7F7AFB280EB4E87A11") to get test ads on this device.
03-15 09:51:46.569: I/Ads(12405): Starting ad request.
03-15 09:51:48.642: I/Ads(12405): No fill from ad server.
03-15 09:51:48.652: W/Ads(12405): Failed to load ad: 3

完整的 logcat 输出

03-15 10:07:56.980: D/IntroActivity(15242): ++onCreate
03-15 10:07:59.432: I/Ads(15242): Use AdRequest.Builder.addTestDevice("A24031FACA2D8B7F7AFB280EB4E87A11") to get test ads on this device.
03-15 10:07:59.442: I/Ads(15242): Starting ad request.
03-15 10:07:59.572: D/webcoreglue(15242): netstack: Memory Cache feature is ON
03-15 10:07:59.953: W/(15242): init htc webcore
03-15 10:08:00.013: E/GooglePlayServicesUtil(15242): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-15 10:08:00.123: I/KENLOG(15242): setSpellCheckEnabled <enabled: false> delay: 1000
03-15 10:08:00.143: I/KENLOG(15242): setSpellCheckEnabled <enabled: true> delay: 1000
03-15 10:08:00.233: I/Adreno200-EGL(15242): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_RB1.04.01.01.06.043_msm8660_surf_JB_REL_RB1.2_CL2428086_release_AU (CL2428086)
03-15 10:08:00.233: I/Adreno200-EGL(15242): Build Date: 11/15/12 Thu
03-15 10:08:00.233: I/Adreno200-EGL(15242): Local Branch:
03-15 10:08:00.233: I/Adreno200-EGL(15242): Remote Branch: m/jb_rel_rb1.2
03-15 10:08:00.233: I/Adreno200-EGL(15242): Local Patches: NONE
03-15 10:08:00.233: I/Adreno200-EGL(15242): Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_RB1.04.01.01.06.043 + e534df6 + 951c251 + 07bf631 + 6aa3ec7 + e04e486 + 9f5646a + 855d11b + NOTHING
03-15 10:08:00.333: D/memalloc(15242): ion: Mapped buffer base:0x5a4a0000 size:2088960 offset:0 fd:86
03-15 10:08:00.333: D/memalloc(15242): ion: Mapped buffer base:0x564cd000 size:4096 offset:0 fd:88
03-15 10:08:00.353: E/GooglePlayServicesUtil(15242): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-15 10:08:00.433: D/memalloc(15242): ion: Mapped buffer base:0x5b4ed000 size:2088960 offset:0 fd:93
03-15 10:08:00.433: D/memalloc(15242): ion: Mapped buffer base:0x56787000 size:4096 offset:0 fd:95
03-15 10:08:00.433: D/HostStatisticManager(15242): netstack: DNS Host Prioritization is: ON, Version: 5.0.1
03-15 10:08:00.433: I/(15242): netstack: LIB_MGR - Lib loaded: libdnshostprio.so
03-15 10:08:00.433: E/(15242): netstack: STAT_HUB - Processor name is undefined
03-15 10:08:00.433: E/(15242): netstack: STAT_HUB - Failed to load plugin: libdnshostprio.so
03-15 10:08:00.433: E/(15242): netstack: LIB_MGR - Error loading lib spl_proc_plugin.so
03-15 10:08:00.433: E/(15242): netstack: STAT_HUB - Failed to load plugin: spl_proc_plugin.so
03-15 10:08:00.443: W/dalvikvm(15242): [GC Control] disableGcForExternalAlloc: false
03-15 10:08:00.453: E/(15242): netstack: LIB_MGR - Error loading lib pp_proc_plugin.so
03-15 10:08:00.453: E/(15242): netstack: STAT_HUB - Failed to load plugin: pp_proc_plugin.so
03-15 10:08:00.453: E/(15242): netstack: STAT_HUB - App quizHarness.quiz isn't supported
03-15 10:08:00.493: E/GooglePlayServicesUtil(15242): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-15 10:08:00.533: D/memalloc(15242): ion: Mapped buffer base:0x5b7eb000 size:2088960 offset:0 fd:92
03-15 10:08:00.533: D/memalloc(15242): ion: Mapped buffer base:0x567dd000 size:4096 offset:0 fd:98
03-15 10:08:00.583: W/(15242): init htc webcore
03-15 10:08:01.234: I/Ads(15242): No fill from ad server.
03-15 10:08:01.254: W/dalvikvm(15242): [GC Control] disableGcForExternalAlloc: false
03-15 10:08:01.254: E/SQLiteLog(15242): (14) cannot open file at line 30178 of [00bb9c9ce4]
03-15 10:08:01.254: E/SQLiteLog(15242): (14) os_unix.c:30178: (2) open(/NotificationPermissions.db) -
03-15 10:08:01.254: D/WebKit(15242): ERROR:
03-15 10:08:01.254: D/WebKit(15242): SQLite database failed to load from /NotificationPermissions.db
03-15 10:08:01.254: D/WebKit(15242): Cause - unable to open database file
03-15 10:08:01.254: D/WebKit(15242): external/webkit/Source/WebCore/platform/sql/SQLiteDatabase.cpp(71) : bool WebCore::SQLiteDatabase::open(const WTF::String&, bool)
03-15 10:08:01.264: W/Ads(15242): Failed to load ad: 3

代码

// Create the adView.
adView = new AdView(this);
adView.setAdUnitId(admobUnitID);
adView.setAdSize(AdSize.BANNER);

// Lookup LinearLayout
LinearLayout layout = (LinearLayout)findViewById(R.id.adLayout);

// Add the adView to it.
layout.addView(adView);

// Initiate a generic request.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // Emulator
.addTestDevice("A24031FACA2D8B7F7AFB280EB4E87A11")
.build();

// Load the adView with the ad request.
adView.loadAd(adRequest);

最佳答案

https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start https://developer.android.com/google/play-services/setup.html

你的代码看起来没问题

这是一个检查 google play 的类。如果未安装 googleplay,它会显示一个对话框,供用户下载。

设置项目以使用 google play 并将此代码添加到 onCreate。

if (!MyGooglePlay.isGooglePlay(getApplicationContext())) {
myGP = new MyGooglePlay(this);
myGP.isGooglePlay();
}

//MyGooglePlay 类

import android.app.Dialog;

import android.content.Context;
import android.content.IntentSender;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;

import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBarActivity;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;

public class MyGooglePlay {

private static final int CONNECTION_FAILURE_RESOLUTION_REQUEST = 8302;
private ActionBarActivity activity;
private FragmentManager fragManager;

public MyGooglePlay(ActionBarActivity activity) {
this.activity = activity;
this.fragManager = activity.getSupportFragmentManager();
}

public static boolean isGooglePlay(Context context) {
return (GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS);
}

public boolean isGooglePlay() {
if (isGooglePlay(activity)) {
return true;
} else {
return checkGooglePlay();
}
}

private static final String DIALOG_ERROR = "dialog_error";

public ErrorDialogFragment errorFragment;

private boolean checkGooglePlay() {
int mIsGooglePlayServicesAvailable = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(activity);

switch (mIsGooglePlayServicesAvailable) {
case ConnectionResult.SUCCESS:
return true;
default:

Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
mIsGooglePlayServicesAvailable, activity,
CONNECTION_FAILURE_RESOLUTION_REQUEST);
// If Google Play services can provide an error dialog
if (errorDialog != null) {
// Create a new DialogFragment for the error dialog
errorFragment = ErrorDialogFragment.newInstance();
// Set the dialog in the DialogFragment
errorFragment.setDialog(errorDialog);

// Show the error dialog in the DialogFragment
errorFragment.show(fragManager, "LocationUpdates");
}
// case ConnectionResult.SERVICE_MISSING:
// case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
// case ConnectionResult.SERVICE_DISABLED:
// case ConnectionResult.SERVICE_INVALID:
// case ConnectionResult.DATE_INVALID:
}

return false;
}

public void dismissMe() {
DialogFragment frag = (DialogFragment) fragManager
.findFragmentByTag("LocationUpdates");
if (frag != null) {
frag.dismissAllowingStateLoss();
}
}

public static class ErrorDialogFragment extends DialogFragment {
// Global field to contain the error dialog
private Dialog mDialog;




static ErrorDialogFragment newInstance() {
ErrorDialogFragment d = new ErrorDialogFragment();
return d;
}

// Default constructor. Sets the dialog field to null
public ErrorDialogFragment() {
super();
mDialog = null;
}

// Set the dialog to display
public void setDialog(Dialog dialog) {
mDialog = dialog;
}


public void onPause(){
super.onPause();
this.dismissAllowingStateLoss();
}

// Return a Dialog to the DialogFragment.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return mDialog;
}
}

public void onConnectionFailed(ConnectionResult connectionResult) {
/*
* Google Play services can resolve some errors it detects. If the error
* has a resolution, try sending an Intent to start a Google Play
* services activity that can resolve error.
*/
if (connectionResult.hasResolution()) {
try {
// Start an Activity that tries to resolve the error
connectionResult.startResolutionForResult(activity,
CONNECTION_FAILURE_RESOLUTION_REQUEST);
/*
* Thrown if Google Play services canceled the original
* PendingIntent
*/
} catch (IntentSender.SendIntentException e) {
// Log the error
e.printStackTrace();
}
} else {
/*
* If no resolution is available, display a dialog to the user with
* the error.
*/
showErrorDialog(connectionResult.getErrorCode(), activity);
}
}

/* Creates a dialog for an error message */
private void showErrorDialog(int errorCode, ActionBarActivity activity) {
// Create a fragment for the error dialog
ErrorDialogFragment dialogFragment = new ErrorDialogFragment();
// Pass the error that should be displayed
Bundle args = new Bundle();
args.putInt(DIALOG_ERROR, errorCode);
dialogFragment.setArguments(args);
dialogFragment
.show(activity.getSupportFragmentManager(), "errordialog");
}

}

关于android - 使用 Google Play 服务的 AdMob - 测试广告 - 广告服务器未填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22422489/

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