如何获得测试广告横幅和测试间质性广告工作的AdMob? [英] How to get test ad Banners and test Interstitial ads working for adMob?

查看:157
本文介绍了如何获得测试广告横幅和测试间质性广告工作的AdMob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装AdMob的广告。我有两个问题:

I am trying to setup adMob ads. I have two questions:

1)我使用adListener接口是否正确? 2)为什么我无法看到的广告插页?

1) Am I using adListener interface correctly? 2) How come I am unable to see ad Interstitials?

让我们开始与adListener。至于我从说明书理解,adListener是一个接口。所以,我创建了一个接口。

Lets start with the adListener. As far as what I understood from the instructions, adListener is an interface. So I created an interface.

import com.google.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public interface AdListener {
    public void onReceiveAd(AdView ad);
    public void onFailedToReceiveAd(AdView ad, AdRequest.ErrorCode error);
    public void onPresentScreen(AdView ad);
    public void onDismissScreen(AdView ad);
    public void onLeaveApplication(AdView ad);
}

然后在我的主类我实现AdListener,有一次我做了我被提示添加未实现的方法(从接口的所有方法)。

Then in my main class I implemented AdListener, and once I did I was prompted to add unimplemented methods (all the methods from the interface).

public class MainActivity extends Activity implements AdListener {
// other code for the body (here). Just showing the methods and implement

@Override
    public void onReceiveAd(AdView ad) {
        Log.d(TAG, "onReceiveAd");
        Toast.makeText(this, "onReceiveAd", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailedToReceiveAd(AdView ad, ErrorCode error) {
        Log.d(TAG, "onFailedToReceiveAd");
        Toast.makeText(this, "onFailedToReceiveAd", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onPresentScreen(AdView ad) {
        Log.d(TAG, "onPresentScreen");
    }

    @Override
    public void onDismissScreen(AdView ad) {
        Log.d(TAG, "onDismissScreen");
    }

    @Override
    public void onLeaveApplication(AdView ad) {
        Log.d(TAG, "onLeaveApplication");
    }
}

我之所以想这样做没有什么,我没有收到我的日志。我说祝酒词双重确认我是不是失去了一些东西。我认为这是另一个步骤我丢失了这个工作。

My reason for thinking this does nothing is that I am not receiving my logs. I added toasts to double confirm I was not missing something. I think there is another step I am missing for this to work.

现在的广告部分。我想我也跟着指示好,我的横幅在实际上工作。但是,我的广告插播不工作。这是我的横幅和间隙。

Now for the ads part. I thought I followed the instructions well, and my banners work in fact. But my ad interstitials do not work. This is what I have for the banners and the interstitials.

从开始code段从我的XML横幅

Starting with code snippet from my xml for the banner

<com.google.android.gms.ads.AdView 
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adUnitId="I_ADDED_CORRECT_ADUNIT_ID"
            ads:adSize="BANNER" />

在我的主要活动,我有以下的code。再次,我想看看测试广告:

In my main Activity, I have the following code. Again, I want to see test ads:

        // setup ad banner and interstitial
        final TelephonyManager tm = (TelephonyManager)getBaseContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
        String testDeviceId = tm.getDeviceId();
        Log.d(TAG, "testDeviceId retrieved(" + testDeviceId + ")");

        // create interstitial
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId("I_ADDED_CORRECT_ADUNIT_ID");

        // ad banner
        adView = (AdView)this.findViewById(R.id.adView);
        // request test interstitial ads
        AdRequest adRequestInterstitial = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(testDeviceId)
            .build();

        // request test banner ads
        AdRequest adRequestBanner = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(testDeviceId)
            .build();

        //load interstitial ads
        interstitial.loadAd(adRequestInterstitial);
        displayInterstitial();

        // load banner ads
        adView.loadAd(adRequestBanner);

    //NOTE: the above code is all in onCreate(). 
    //diaplayInterstitial is outside of onCreate()

    public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            Log.d(TAG, "displayInterstitial()");
            interstitial.show();
        }
    }

让我们来看看还有什么要告诉你?噢,是的!我也有权限已经在清单中设置。权限= INTERNET,ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,READ_PHONE_STATE。

Lets see what else to tell you? Awww, yes! I also have the permissions already set in the manifest. Permissions = INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, READ_PHONE_STATE.

我去项目属性,并且增加了谷歌播放的,services_lib

I went to project properties and added the google-play-services_lib

这是我的全部设置!我已经尝试了一些事情,因为我有一些感情是什么可能是问题。首先,我想,也许测试的广告横幅和测试广告插播不能同时申请。让我感动间质性code到ONSTART()。不过,我不知道这是否是必要的,有益的或更差(和它没有工作!)。我的第二个想法是,一​​切工作正常,有一次我出版我的应用程序都将是不错的。但不管,我的日志不会工作的AdListener。如果我可以做到这一点去,我想我可以开始与正在发生的事情更有信心验证。

This is my whole setup! I have tried a number of things, because I had some 'feelings' about what may be the issue. First, I thought that maybe test ad banners and test ad interstitials cannot be requested at the same time. So I moved interstitial code to onStart(). But then, I was not sure if this was necessary, beneficial or worse (and it did not work!). My second thought was that everything works fine, and once I publish my app all will be good. But regardless, my logs are not working for the AdListener. If I can get that going, I think I can start verifying with more confidence of what is going on.

感谢您在您的帮助。

日志SS

Log SS

推荐答案

好了,下面几个问题。

1)不,你不使用AdListener接口正确。 不要创建自己的界面。 AdMob的已经提供了AdListener接口。你需要但是实现它。

1) No you are not using the AdListener interface correctly. Don't create your own interface. AdMob already supplies an AdListener interface. You do need to implement it however.

NB个人而言,我会创建一个匿名实现AdListener,而不是将其添加到活动的,但是这是一个设计的设计为你自己。

NB personally I would create an anonymous implementation of the AdListener instead of adding it to the Activity, but that's a design design for yourself.

接下来,您需要将您的监听器连接到你的AD浏览报。因此,在您#onCreate

Next you need to attach your listener to your AdView. So in your #onCreate

// load banner ads
adView.setAdListener(new AdListener() {
   ...
});
adView.loadAd(adRequestBanner);

2)你不可能看到任何插页与code以上,因为你正试图请求后立即显示。这是极不可能的间质已经被下载在这短短的时间框架。在任何情况下,你真的不希望显示在创建你的活动间质性每一次,这是一个不好的用户体验。

2) You are unlikely to see any Interstitials with the code above because you are attempting to display immediately after requesting. It is extremely unlikely that an Interstitial has been downloaded in that short time frame. And in any case you really don't want to display an interstitial every time your Activity is created, it is a poor user experience.

将您的来电displayInterstitial()在您的应用程序生命周期的以后某个时间,这样在游戏会话结束或级别等之间。

Move your call to displayInterstitial() to some later point in your app life cycle, such at the end of a game session or between levels etc.

这篇关于如何获得测试广告横幅和测试间质性广告工作的AdMob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆