java.lang.SecurityException: getDeviceId: The user 10158 does not meet the requirements to access de
·
问题
执行获取Android设备的deviceId,获取设备的标识号
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String DEVICE_ID = manager.getDeviceId();
结果报错java.lang.SecurityException: getDeviceId: The user 10158 does not meet the requirements to access device identifiers.
百度后明白问题的所在,是targetSdkVersion版本太高了,从官方文档中发现以下信息
Android 10(API 级别 29)对不可重置的标识符(包括 IMEI 和序列号)添加了限制。您的应用必须是设备或个人资料所有者应用,具有特殊运营商权限或具有
READ_PRIVILEGED_PHONE_STATE特许权限,才能访问这些标识符。
解决方案
有两种方法,一种是降低targetSdkVersion的版本,降至到低版本,还一钟是获取serial号进行设备标识,具体代码请看我的另一篇文章
Android获取设备号标识符
更多推荐


所有评论(0)