2011-03-09 95 views

回答

-1

喜記下我的回答,如果你想獲得設備ID, 可以使用TelephonyManager爲我所用下面

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

您還需要以下權限添加到您的清單:

<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
+1

但這不是Admob使用的id。 – dongshengcn 2011-03-09 19:12:12

+1

這不是正確的號碼。不確定AdMob使用的是什麼,但不是這個。 – theblitz 2011-06-05 19:19:20

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

我希望這會幫助你;)

+0

非常感謝。很棒! – Sileria 2012-01-25 17:48:27

+0

這是答案。在4.0+ Nexus Galaxy上測試。 – 2012-10-11 16:37:05

相關問題