Android 10中没有针对Android开发人员的IMEI [英] No IMEI for Android Developers in Android 10

查看:1232
本文介绍了Android 10中没有针对Android开发人员的IMEI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Android十分重视安全性,并试图使新的android版本更加安全,因此开发人员很难及时了解新的安全功能并寻找替代方法以使其应用程序与旧功能兼容.

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.

这个问题与新Android 10中的IMEI有关! 使用下面的代码,旧方法超级容易获得IMEI号码

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();
    }

在新版Android 10中,现在仅限获取IMEI号码.根据android文档

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

应用必须具有READ_PRIVILEGED_PHONE_STATE特权,才能访问设备的不可重置标识符,包括IMEI和序列号.

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.

我想使我的应用程序与Android 10兼容,并希望获得IMEI.如何在不成为设备​​所有者或个人资料所有者的情况下获取Android 10中的IMEI号码?

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 ?

推荐答案

仅设备所有者应用可以读取唯一标识符,或者您的应用必须是具有READ_PRIVILEGED_PHONE_STATE的系统应用.您不能要求普通应用程序具有此权限.

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 10中没有针对Android开发人员的IMEI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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