Hãy xem xét trường hợp của tôi:
Same serial number on several android devices. Adb is useless. How can I change the serial number?
Vì vậy, tôi did'nt giải quyết vấn đề với ADB nhưng để xác định một thiết bị Android của tôi sử dụng mã này (sử dụng getDeviceId(context)
):
public static String getDeviceId(Context context) {
String id = getUniqueID(context);
if (id == null)
id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
return id;
}
private static String getUniqueID(Context context) {
String telephonyDeviceId = "NoTelephonyId";
String androidDeviceId = "NoAndroidId";
// get telephony id
try {
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyDeviceId = tm.getDeviceId();
if (telephonyDeviceId == null) {
telephonyDeviceId = "NoTelephonyId";
}
} catch (Exception e) {
}
// get internal android device id
try {
androidDeviceId = android.provider.Settings.Secure.getString(context.getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID);
if (androidDeviceId == null) {
androidDeviceId = "NoAndroidId";
}
} catch (Exception e) {
}
// build up the uuid
try {
String id = getStringIntegerHexBlocks(androidDeviceId.hashCode())
+ "-"
+ getStringIntegerHexBlocks(telephonyDeviceId.hashCode());
return id;
} catch (Exception e) {
return "0000-0000-1111-1111";
}
}
public static String getStringIntegerHexBlocks(int value) {
String result = "";
String string = Integer.toHexString(value);
int remain = 8 - string.length();
char[] chars = new char[remain];
Arrays.fill(chars, '0');
string = new String(chars) + string;
int count = 0;
for (int i = string.length() - 1; i >= 0; i--) {
count++;
result = string.substring(i, i + 1) + result;
if (count == 4) {
result = "-" + result;
count = 0;
}
}
if (result.startsWith("-")) {
result = result.substring(1, result.length());
}
return result;
}
Tôi sử dụng nó để xác định một cài đặt ứng dụng cụ thể khi gọi các dịch vụ web của tôi. Như bạn có thể thấy tôi cố gắng phê duyệt khác nhau, dựa trên TelephonyManager và ANDROID_ID.
Tôi nhận được một chuỗi như xxxx-xxxx-xxxx-xxxx trong đó x là ký tự hex.
Tôi mua rất nhiều thuốc Trung Quốc chi phí thấp và tất cả trong số này có cùng DEVICE_ID và số serial cùng !! Vì vậy, giải pháp của tôi. Nó hoạt động tốt ngay bây giờ.
Nguồn
2013-06-11 14:32:35
Bạn nói rằng bạn theo dõi cài đặt ứng dụng độc đáo. Nó sẽ không được dễ dàng hơn chỉ để tiết kiệm một số chuỗi generatad để sở thích chia sẻ, nếu một không được lưu lại, và sử dụng nó? Tôi có nghĩa là như sử dụng một boolean idGenerated, khi lần đầu tiên tạo ra đặt nó thành sự thật, và nếu nó là đúng thì lấy id từ sharedpreferences, theo cách này bạn sẽ có một id cài đặt duy nhất cho mỗi lần cài đặt. – lxknvlk
@lxknvlk Tôi cần cùng một id nếu tôi gỡ cài đặt ứng dụng và cài đặt lại nó. –