我是靠谱客的博主 大意母鸡,最近开发中收集的这篇文章主要介绍android获取imei兼容,Android 10中没有针对Android开发人员的IMEI,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

As Android is serious about security and trying to make new android versions more secure, its becoming tough for developers to keep up-to date with new security features and find old methods alternatives to make their app compatible with old features.

This question is about IMEI in New Android 10!

The old method was super easy to get IMEI number by using below code

String deviceId = "";

if (Build.VERSION.SDK_INT >= 26) {

if (telMgr.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {

deviceId = telMgr.getMeid();

} else if (telMgr.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {

deviceId = telMgr.getImei();

} else {

deviceId = ""; // default!!!

}

} else {

deviceId = telMgr.getDeviceId();

}

In New Android 10 it is now restricted to get IMEI number. According to android documentation

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.

The problem is that when we try to ask run time permissions with

android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE

My compiler does not recognize this permissions and i got error on this line but when i ask this permission in manifest file it does recognize this line but through warning that this permission is only for system apps.

I want to make my app compatible with Android 10 and want to get IMEI. How can i get IMEI number in Android 10 without becoming device owner or profile owner ?

解决方案

Only device owner apps can read unique identifiers or your app must be a system app with READ_PRIVILEGED_PHONE_STATE. You can't ask this permission for a normal app.

最后

以上就是大意母鸡为你收集整理的android获取imei兼容,Android 10中没有针对Android开发人员的IMEI的全部内容,希望文章能够帮你解决android获取imei兼容,Android 10中没有针对Android开发人员的IMEI所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部