是否有任何AdMob虚拟ID? [英] Is there any AdMob dummy id?

查看:91
本文介绍了是否有任何AdMob虚拟ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有用于测试目的的AdMob虚拟ID?
我需要注册应用程序吗?得到MY_AD_UNIT_ID?

Is there any AdMob dummy ids for testing purpose? Do I need to register app & get MY_AD_UNIT_ID?

推荐答案

本身没有虚拟ID。您需要设置XML或JAVA代码才能获得测试广告。要在测试期间获取测试广告,请将以下内容添加到XML中,在其中声明了 AdView

There aren't dummy ID's per se. You need to setup the XML or the JAVA code to get test ads. To get Test Ads during testing, add the following to your XML where you have the AdView declared.

注意:我只使用XML代码在应用中显示广告。

NOTE: I use just the XML code to display Ads in my app.

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom|center"
    android:orientation="horizontal" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="YOUR_AD_UNIT_ID"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR, YOUR_DEVICE_ID" >
    </com.google.ads.AdView>
</LinearLayout>

要通过JAVA设置测试单元(仿真器和设备):

To set the Test Unit (Both the emulator and your devices) from JAVA:

AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);            
adRequest.addTestDevice("test");

要获取设备ID,您可以使用以下命令:

To get your Device ID, you can use this:

final TelephonyManager tm = (TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
String deviceid = tm.getDeviceId();

来自: https://stackoverflow.com/a/9681517/450534

编辑:错过了第二个问题。

是。您需要在Ad-Mob帐户中注册您的应用。如果没有注册,您将不会获得广告单元ID,因此您的应用程序中也没有广告。

Yes. You will need to register your app in your Ad-Mob account. Without that being registered, you won't be getting your Ad Unit ID and therefore, no Ads in your app either.

更新:发布此答案两年后,Google在其admob SDK中添加了一些虚拟ID。有关虚拟ID的信息,请参考其他获得较好投票的答案

UPDATE: Approximately two years after posting this answer, Google added a few dummy ID's to their admob SDK. Please refer to the other better voted answers for the dummy ID's

这篇关于是否有任何AdMob虚拟ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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