为什么返回settings.secure.getString(context.getContentResolver(),



我正在使用

Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

但是返回的值是空的。

有什么想法吗?

谢谢

您是否正在使用仿真器?模拟器返回此系统属性的空值/空值。

此外,有趣的是注意一些Android/Google警告有关Android_id使用的情况

android_id对于唯一的设备标识符来说似乎是一个不错的选择。那里 是不利的:首先,在Android版本上,它不是100%可靠的 在2.2之前(" Froyo"(。另外,至少有一个 主要制造商的流行手机中广泛观察的虫子, 每个实例都有相同的android_id。

此外,请注意此警告,如果您的应用程序针对Android Oreo或以上

注意:对于在将设备更新为之前安装的应用程序 Android 8.0(API级26(或更高版本 Android_id如果应用程序卸载,然后重新安装 OTA之后。在OTA之后保留跨卸载的值 Android 8.0或更高版本,开发人员可以使用密钥/值备份。

 public static String getDeviceID(Context Ctx) {
    String android_id = Secure.getString(Ctx.getContentResolver(),
            Secure.ANDROID_ID);
    return android_id;
}
public static String getImeiNumber(Context Ctx) {
    final TelephonyManager telephonyManager = (TelephonyManager) Ctx.getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        //getDeviceId() is Deprecated so for android O we can use getImei() method
        return telephonyManager.getImei();
    } else {
        return getDeviceID(Ctx);
    }
}

最新更新