Android Tablet - Get Unique Device ID
How do we get Unique Device ID fr开发者_JAVA百科om the Android Tablets (Android 3.0 SDK HoneyComb)?
I have also found that we can get Android Device ID which is unique by using: String deviceId = Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);
But Here its written that Although, it is not guaranteed that the Android ID will be an unique identifier.
.
I have also gone through the some SO Questions:
- Is there a unique Android device ID?
- How to find serial number of Android device?
And also referred this article: http://android-developers.blogspot.com/2011/03/identifying-app-installations.html.
But i am confused how do we get/have Unique Device ID from the Android Tablet type of Device?
I know this question is old but it might through off somebody that finds it since android ID has no guarantee to work, it might even be null in some cases or easily changed on rooted phones.
What I did was combine the Android ID with the WiFi MAC address in a method that generates a UUID:
private void generateDeviceId() {
final String macAddr, androidId;
WifiManager wifiMan = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
macAddr = wifiInf.getMacAddress();
androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), macAddr.hashCode());
// Maybe save this: deviceUuid.toString()); to the preferences.
}
Dont forget to add the permissions to the AndroidManifest.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Good luck!
Starting with Android 2.2, ANDROID_ID is pretty much guaranteed to be unique.
There was an article about that on the Android developer blog very recently.
精彩评论