How to programmatically get the Device ID for Admo

2019-03-29 08:15发布

I have multiple devices, and I probably will have more, and do not want to add them one by one. Does anybody know what ID Admob uses?

3条回答
对你真心纯属浪费
2楼-- · 2019-03-29 09:06

Hi Note Down My answer ,if you want to get Device id, you can use TelephonyManager as i used below

String device_id=null;
TelephonyManager telemngr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
device_id=telemngr.getDeviceId();

You also need to add the following permission to your manifest:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
查看更多
戒情不戒烟
3楼-- · 2019-03-29 09:15
String aid = Settings.Secure.getString(getContext().getContentResolver(), "android_id");

Object obj = null;
try {
    ((MessageDigest) (obj = MessageDigest.getInstance("MD5"))).update(
                                   aid.getBytes(), 0, aid.length());

    obj = String.format("%032X", new Object[] { new BigInteger(1,
                                   ((MessageDigest) obj).digest()) });
} catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
    obj = aid.substring(0, 32);
}

I hope this will help you ;)

查看更多
迷人小祖宗
4楼-- · 2019-03-29 09:19

I tried that and it gave me the Hex value for my ESN number. This is not the number AdMob uses.

When requesting an ad, in the Dalvic Debug Monitor log it shows you the number to use.

Also you might want to refer to the following page (about half way down): http://code.google.com/mobile/ads/docs/android/intermediate.html

查看更多
登录 后发表回答