1.获取OAID,IMEI.2.友盟SDK升级,bugfix
This commit is contained in:
@@ -10,6 +10,7 @@ import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -17,8 +18,37 @@ import java.util.UUID;
|
||||
*/
|
||||
|
||||
public class DeviceUuidFactory {
|
||||
protected static final String PREFS_FILE = "device_id.xml";
|
||||
protected static final String PREFS_DEVICE_ID = "device_id";
|
||||
private static final String PREFS_FILE = "device_id.xml";
|
||||
private static final String PREFS_DEVICE_ID = "device_id";
|
||||
|
||||
public static String getDeviceId(Context context) {
|
||||
UUID uuid;
|
||||
synchronized (DeviceUuidFactory.class) {
|
||||
final SharedPreferences prefs = context.getSharedPreferences(PREFS_FILE, 0);
|
||||
final String id = prefs.getString(PREFS_DEVICE_ID, null);
|
||||
if (id != null) {
|
||||
// Use the ids previously computed and stored in the prefs file
|
||||
uuid = UUID.fromString(id);
|
||||
} else {
|
||||
final String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
// Use the Android ID unless it's broken, in which case fallback on deviceId,
|
||||
// unless it's not available, then fallback on a random number which we store
|
||||
// to a prefs file
|
||||
if (!"9774d56d682e549c".equals(androidId)) {
|
||||
uuid = UUID.nameUUIDFromBytes(androidId.getBytes(StandardCharsets.UTF_8));
|
||||
} else {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
// Write the value out to the prefs file
|
||||
prefs.edit().putString(PREFS_DEVICE_ID, uuid.toString()).apply();
|
||||
}
|
||||
}
|
||||
if (uuid == null) {
|
||||
return "";
|
||||
} else {
|
||||
return uuid.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unique UUID for the current android device. As with all UUIDs, this unique ID is "very highly likely"
|
||||
@@ -43,38 +73,5 @@ public class DeviceUuidFactory {
|
||||
*
|
||||
* @return a UUID that may be used to uniquely identify your device for most purposes.
|
||||
*/
|
||||
public static String getDeviceId(Context context) {
|
||||
UUID uuid = null;
|
||||
synchronized (DeviceUuidFactory.class) {
|
||||
final SharedPreferences prefs = context.getSharedPreferences(PREFS_FILE, 0);
|
||||
final String id = prefs.getString(PREFS_DEVICE_ID, null);
|
||||
if (id != null) {
|
||||
// Use the ids previously computed and stored in the prefs file
|
||||
uuid = UUID.fromString(id);
|
||||
} else {
|
||||
final String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
// Use the Android ID unless it's broken, in which case fallback on deviceId,
|
||||
// unless it's not available, then fallback on a random number which we store
|
||||
// to a prefs file
|
||||
try {
|
||||
if (!"9774d56d682e549c".equals(androidId)) {
|
||||
uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
|
||||
} else {
|
||||
final String deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
|
||||
uuid = deviceId != null ? UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")) : UUID.randomUUID();
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// Write the value out to the prefs file
|
||||
prefs.edit().putString(PREFS_DEVICE_ID, uuid.toString()).commit();
|
||||
}
|
||||
}
|
||||
if (uuid == null) {
|
||||
return "";
|
||||
} else {
|
||||
return uuid.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user