I need an ID which will be unique for each device. This ID will be stored in the server and will be used to identify a device. I am thinking of using IMEI number but I dont want to send the IMEI number to server for privacy reason.
So, I am thinking of doing this
- Get IMEI number.
- Hash the IMEI number using SHA-1.
- Send this to server
Is this a reliable way of getting unique device ID without privacy concerns? Please advice.
Get IMEI number using following
String identifier = null;
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (tm != null)
identifier = tm.getDeviceId();
if (identifier == null || identifier .length() == 0)
identifier = Secure.getString(activity.getContentResolver(),Secure.ANDROID_ID);
and add this permission :
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
You can use the ANDROID_ID but in certain devices it is a bug and it seems to return the same id. Check the reference for the same https://groups.google.com/forum/#!topic/android-developers/U4mOUI-rRPY . As a fall back i do the following:
String deviceId = Secure.getString(ActivationActivity.this.getContentResolver(), Secure.ANDROID_ID);
if ("9774d56d682e549c".equals(deviceId)) {
deviceId= UUID.randomUUID().toString();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.