How to programmatically get the Device ID for Admob?
I have multiple devices, and I probably will have mo开发者_运维百科re, and do not want to add them one by one. Does anybody know what ID Admob uses?
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 ;)
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
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" />
精彩评论