简体   繁体   English

如何在Android 10中获取IMEI

[英]How to get IMEI in android 10

For security purposes, I want to store the IMEI number of app users but I am getting the following error出于安全考虑,我想存储应用程序用户的 IMEI 号码,但出现以下错误

2020-02-14 13:29:36.620 14794-14794/com.udaan.android.creditoperations E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.udaan.android.creditoperations, PID: 14794
    java.lang.SecurityException: getImeiForSlot: The user 10643 does not meet the requirements to access device identifiers.
        at android.os.Parcel.createException(Parcel.java:2071)
        at android.os.Parcel.readException(Parcel.java:2039)
        at android.os.Parcel.readException(Parcel.java:1987)
        at com.android.internal.telephony.ITelephony$Stub$Proxy.getImeiForSlot(ITelephony.java:10471)
        at android.telephony.TelephonyManager.getImei(TelephonyManager.java:1754)
        at android.telephony.TelephonyManager.getImei(TelephonyManager.java:1715)

Is there any way to access IMEI number including latest android devices?有没有办法访问 IMEI 号码,包括最新的安卓设备?

Starting from Android 10, Third-party apps installed from the Google Play Store cannot get IMEI number.从 Android 10 开始,从 Google Play 商店安装的第三方应用程序无法获取 IMEI 号码。 That's why you are getting this Security Exception.这就是您收到此安全异常的原因。

I would suggest you use any other unique id for your purpose.我建议您为您的目的使用任何其他唯一 ID。 For best practices of unique identifiers recommended by Google, you can check out the below link有关 Google 推荐的唯一标识符的最佳做法,您可以查看以下链接

https://developer.android.com/training/articles/user-data-ids https://developer.android.com/training/articles/user-data-ids

您是否尝试过为 AndroidManifest 文件添加权限?

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

From Android 10, there is no way to get it.从 Android 10 开始,无法获得它。 Find an alternative unique identifier from document which shared by Abhishek.从 Abhishek 共享的文档中查找替代的唯一标识符。

Starting in Android 10, apps must have the READ_PRIVILEGED_PHONE_STATE privileged permission in order to access the device's non-resettable identifiers, which include both IMEI and serial number.从 Android 10 开始,应用必须具有 READ_PRIVILEGED_PHONE_STATE 特权才能访问设备的不可重置标识符,包括 IMEI 和序列号。

Caution: Third-party apps installed from the Google Play Store cannot declare privileged permissions.注意:从 Google Play 商店安装的第三方应用程序不能声明特权权限。

More details;更多细节;

https://developer.android.com/about/versions/10/privacy/changes https://developer.android.com/about/versions/10/privacy/changes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM