DeviceIdFactory.java
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.cnlive.goldenline.cmsdk;
import android.content.Context;
import android.support.annotation.NonNull;
import android.telephony.TelephonyManager;
import android.util.Log;
import java.util.UUID;
public class DeviceIdFactory {
public static final String TAG = "DeviceIdFactory";
public static String getDeviceId(@NonNull Context context) {
final TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = ""
+ android.provider.Settings.Secure.getString(
context.getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID);
String formatStr = String.format("deviceId=%s, serialNumber=%s, androidId=%s", tmDevice, tmSerial, androidId);
Log.d(TAG, formatStr);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
String uniqueId = deviceUuid.toString();
Log.d(TAG, "deviceUuid=" + deviceUuid);
return uniqueId;
}
}