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

问题描述 投票:0回答:3

早上好,

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

发展信息

我使用Eclipse进行开发。

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

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

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

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

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

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

我尝试了很多事情:

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

我根本无法探究这个问题的真相。我将非常感谢任何能在这里帮助我的人。我有一种感觉,我可能错过了一些非常小但很重要的事情,导致了我这些问题。

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

无论如何,我认为这就是我所掌握的所有信息 - 提前感谢任何为我研究此问题的人。

过滤日志

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

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);
android eclipse admob google-play-services
3个回答
5
投票

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

}

0
投票

几周前回到这个项目后,我在项目中创建了一个新模块,复制了我用于旧模块(其中广告不会加载)的所有代码,并且广告起作用了。

我一直没有找到原来问题的原因,直到现在:

编辑: 在 AndroidStudio 中重新创建模块时,我注意到“applicationid”替换了 包名称,当我使applicationid与我过去在eclipse中使用的包名称匹配时,问题又回来了。 很多人挠头,我发现了一个类似的问题和这个答案https://stackoverflow.com/a/26830390/2530792我记得很多个月前,我收到了来自admob的广告块。我当时申诉过,后来忘记了,但肯定是这个问题。

显然我无法使用不同的 applicationid 更新应用程序,因此我将重新上诉该阻止(希望不会太晚 - 我仍然有电子邮件),如果失败,将需要转向替代方案到 AdMob。

再次感谢您的帮助。


0
投票

如果您使用

com.example.appname
启动项目,则可能会返回“无填充”错误。要解决此问题,请转到应用程序级别
gradle
文件并将应用程序 ID 更改为类似
com.yourownpackagename.adapp
的内容。如果您的应用程序 ID 为
com.example.adapp
,它可能不会加载任何广告,或者可能返回“未填充”错误。因此,不要使用
example
作为包名称。 另一个建议是始终使用您自己的包名称创建项目。

© www.soinside.com 2019 - 2024. All rights reserved.