Hi
Today, I would like to share some piece of code which can be used as unique id in android
Today, I would like to share some piece of code which can be used as unique id in android
/**
* Its nothing but combine the Android ID with the WiFi MAC address in a
* method that generates a UUID: Required Permition : <uses-permission
* android:name="android.permission.ACCESS_WIFI_STATE" />
*
* @param activity
* @return
*/
public static String getUniqueID(Activity activity) {
final String macAddr, androidId;
WifiManager wifiMan = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
macAddr = wifiInf.getMacAddress();
androidId = "" + android.provider.Settings.Secure.getString(activity.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
String UUID = androidId.hashCode() + "" + macAddr.hashCode();
// Maybe save this: deviceUuid.toString()); to the preferences.
return UUID;
}
I hope this might useful for some cases, Happy Codding
No comments:
Post a Comment