在Android 10中,getDeviceID值为null [英] In Android 10 getDeviceID value is null

查看:1420
本文介绍了在Android 10中,getDeviceID值为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在android 10中,无法使用权​​限"READ_PHONE_STATE"获取设备ID.尝试获取设备ID"用户10296不符合访问设备标识符的要求"时出现错误.我提到了开发者网站,但无法获得适当的解决方案.同样也无法访问" READ_PRIVILEGE_PHONE_STATE "权限.

In android 10, couldn't get device id using permission "READ_PHONE_STATE". I got an error while trying to get deviceID "The user 10296 does not meet the requirements to access device identifiers". I referred the developer site, but couldn't get proper solution. Also "READ_PRIVILEGE_PHONE_STATE" permission also not accessible.

请使用任何解决方案从Android 10移动版获取deviceID,并帮助我解决此问题. 预先感谢

Please prefer any solution to get deviceID from Android 10 mobile's and help me to resolve this issue. Thanks in advance

推荐答案

getDeviceId() .

getDeviceId() has been deprecated since API level 26.

"READ_PRIVILEGE_PHONE_STATE"仅可通过
访问.最佳实践建议您应避免使用硬件标识符".唯一标识符.您可以使用Firebase中的实例ID,例如FirebaseInstanceId.getInstance().getId();.

或者您可以生成自定义的全局唯一ID(GUID)以唯一标识应用实例,例如 String uniqueID = UUID.randomUUID().toString();

Or you can generate a custom globally-unique ID (GUID) to uniquely identify the app instance e.g String uniqueID = UUID.randomUUID().toString();

或最不推荐的方法

String deviceId = android.provider.Settings.Secure.getString(
                context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

这篇关于在Android 10中,getDeviceID值为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆