如何获取Admob需要的的test device ID

官方指南说


请求一个广告就会打印id出来


he alternative way of serving test ads is to keep your regular ad unit ID, but configure your device as a test device. When a device is configured as a test device, the Google Mobile Ads SDK automatically substitutes in the aforementioned sample ad unit ID, limiting that device to receiving test ads.


Follow the steps below to configure your device as a test device.


Note: Android emulators are automatically configured as test devices.
Add your test device


Load your ads-integrated app and make an ad request.
Check the logcat output for a message that looks like this:
I/Ads: Use AdRequest.Builder.addTestDevice("33BE2250B43518CCDA7DE426D04EE232")
to get test ads on this device.
Copy your test device ID to your clipboard.
Modify your code to call AdRequest.Builder.addTestDevice() with your test device ID. This method can be called multiple times for multiple devices.
AdRequest request = new AdRequest.Builder()
    .addTestDevice("33BE2250B43518CCDA7DE426D04EE232")
    .build();
You can optionally check request.isTestDevice() to confirm that your device was properly added as a test device.


Note: Be sure to remove the code that sets these test devices before you release your app.




但是我的手机没输出

酷派的手机好像 屏蔽了i级别的打印.


下面是网上查到的方法, 用代码获取id.


源地址


The accepted answers will work if you are only testing on the Emulator or on a few devices, but if you are testing on a plethora of devices, you may need some means of prorammatically adding the running device's device ID.


The following code will make the current running device into an adview test device programmatically

if(YourApplication.debugEnabled(this)) //debug flag from somewhere that you set
    {

        String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        String deviceId = md5(android_id).toUpperCase();
        mAdRequest.addTestDevice(deviceId);
        boolean isTestDevice = mAdRequest.isTestDevice(this);

        Log.v(TAG, "is Admob Test Device ? "+deviceId+" "+isTestDevice); //to confirm it worked
    }
You need to use the md5 of the Android ID, and it needs to be upper case. Here is the md5 code I used

public static final String md5(final String s) {
    try {
        // Create MD5 Hash
        MessageDigest digest = java.security.MessageDigest
                .getInstance("MD5");
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            String h = Integer.toHexString(0xFF & messageDigest[i]);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        Logger.logStackTrace(TAG,e);
    }
    return "";
}

我用其他人的一加手机测试, 获得的ID和logcat打印的是一样的.

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
原创:officemaster.cn 转载请注明出处:http://officemaster.cn/forum.php?mod=viewthread&tid=6116&extra=page%3D1 Unity 通过Unity Admob Plugin插件集成admob教程 下载Unity Admob Demo,插件里面包含 Admob_Unity_Demo.unitypackage 插件文件 AdmobPluginRes 是Admob 的ios sdk和插件使用样例代码 打开样例代码可以看到代码里面如何使用Unity Admob插件 把Admob Unity插件添加进unity工程 1. 打开Unity工程 2. 从菜单打开,Assets -> Import Package -> Custom Package. 3. 选中Unity插件文件Admob_Unity_Demo.unitypackage 4. 选择导入所有内容,把admob unity插件内全部内容导入导unity工程 5. 修改admobdemo.cs里面的admob的参数 6. 把addmobdemo.cs 添加到main camera或者其他在场景中一直存在物体上 7. 打开file build and run选择android或者ios平台然后进行设置平台设置 8. 点击build或者build and run编译项目获得xcode工程或者apk,把apk安装到设备上查看下过 如果是ios项目,编译后得到的是xcode工程,为了能正常工作需要进行如下处理 1.把admobpluginres目录下的GoogleMobileAds.framework直接拖拽(一定要拖,不要添加,否则报错)添加到项目根目录下2.给工程添加framework 引用,包括下面的 AdSupport.framework,EventKit.framework,EventKitUI.framework,CoreTelephony.framework,StoreKit.framework,MessageUI.framework 3.编译xcode工程为ipa,安装到设备后运行查看效果 注意:需要设置【Build Settings】 - 【Build Options】 - 【Enable Bitcode】为 “No”, 否则有可能报错 怎么在Unity应用里面集成Admob全屏广告?下面的Unity3d里面添加admob广告的代码 using admob; ... Admob.Instance().initAdmob("admob banner id", "admob interstitial id");//initAdmob just need call once,if you called when create banner ,you not need call any more Admob.Instance().loadInterstitial(); 和横幅广告不同,全屏广告需要先加载,等加载完成后在合适的时间点展示广告 if (Admob.Instance().isInterstitialReady()) { Admob.Instance().showInterstitial(); } 下面分享Unity 集成admob横幅 广告的代码 using admob; ... Admob.Instance().initAdmob("admob banner id", "admob interstitial id");//admob id with format ca-app-pub-2796046890663330/756767388//初始化设置广告 Admob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);//在应用底部居中相对位置展示横幅广告 AdSize.Banner表示展示的广告尺寸,AdPosition.BOTTOM_CENTER表示横幅的放置位置,AdPosition里面包含各个广告位置常量,AdSize包含各个广告尺寸常量 自定义横幅广告尺寸 In addition to constants on _AdSize_, you can also create a custom size: 除了AdSize里面的admob横幅广告外,你也可以自定义广告尺寸,当然这些尺寸必须是admob平台支持的,下面自定义个250x250的广告并展示 using admob; ... //Create a 250x250 banner. AdSize adSize = new AdSize(250, 250); Admob.Instance().showBannerAbsolute(adSize,0,30); 横幅广告相对位置 The following constants list the available ad positions: 下面是所有支持的admob横幅广告相对位置常量 AdPosition.TOP_LEFT AdPosition.TOP_CENTER AdPosition.TOP_RIGHT AdPosition.MIDDLE_LEFT AdPosition.MIDDLE_CENTER AdPosition.MIDDLE_RIGHT AdPosition.BOTTOM_LEFT AdPosition.BOTTOM_CENTER AdPosition.BOTTOM_RIGHT 默认横幅广告展示后就一直是可见的,如果想隐藏广告那可以通过下面的方式进行 Admob.Instance().removeBanner(); 设置admob广告测试模式和儿童应用设置 可能你会想先测试admob广告,那么你可以使用测试模式,或者你的应用是儿童应用,需要设置儿童应用模式可以通过下面的方法进行 using admob; ... Admob.Instance().setTesting(true); Admob.Instance().setForChildren(true); Admob横幅广告和全屏广告都有差不多的广告事件,你可以在unity3d里面监听并处理所有admob广告事件 下面是一个处理全屏广告事件的例子,我们在收到广告的时候就展示广告 using admob; ... Admob.Instance().interstitialEventHandler += onInterstitialEvent; ... void onInterstitialEvent(string eventName, string msg) { Debug.Log("handler onAdmobEvent---" + eventName + " " + msg); if (eventName == AdmobEvent.onAdLoaded) { Admob.Instance().showInterstitial(); } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值