使用Google Play服务的AdMob - 测试广告 - 无法从广告服务器填充

mik*_*_83 14 eclipse android admob google-play-services

早上好,

我的问题是广告根本没有在我的应用,测试模式中显示.我将把这个问题专门用于测试模式,一旦我开始工作,我会担心实时广告.

发展信息

我正在使用Eclipse进行开发.

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

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

我正在使用真实设备进行测试.适用于Android 4.1.2的HTC Sensation.广告适用于设备上安装的其他应用.

问题(见下面的日志信息)

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

我搜索过高低,并发现了很多类似的问题,但我还没有找到这个具体问题的答案.

我尝试了很多东西:

  • 在模拟器中运行(这里发布在我的旧慢速笔记本电脑上运行更新版本的Android).同样的问题.
  • 从头开始重写整个广告代码.
  • 重新导入Google Play服务.
  • 重新安装eclipse - 现在使用最新的Android Developer Tools.
  • 下载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
Run Code Online (Sandbox Code Playgroud)

完整的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
Run Code Online (Sandbox Code Playgroud)

// 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);
Run Code Online (Sandbox Code Playgroud)

dan*_*117 5

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

你的代码看起来不错

这是一个检查谷歌播放的课程.如果未安装googleplay,则会显示一个用户可以下载的对话框.

设置项目以使用谷歌播放并将此代码添加到onCreate.

if (!MyGooglePlay.isGooglePlay(getApplicationContext())) {
        myGP = new MyGooglePlay(this);
        myGP.isGooglePlay();
    }
Run Code Online (Sandbox Code Playgroud)

//类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");
    }

}
Run Code Online (Sandbox Code Playgroud)