How to programmatically get the Device ID for Admob?

百般思念 提交于 2019-12-09 13:07:12

问题


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?


回答1:


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




回答2:


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




回答3:


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" />


来源:https://stackoverflow.com/questions/5249965/how-to-programmatically-get-the-device-id-for-admob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!