今天我们学习打卡的内容是:Android 10.0 app获取不到序列号解决方案

那直接进入分享:

知识Android 10.0 app获取不到序列号解决方案:
在日常生活10.0定制化开发中,在app开发过程中 会遇到获取系列号总是返回unknow 的情况 即使app是系统内置app 也会出现这样的情况 找寻原因找了好久。

(序列号:序列号也称作“机器码”,为一样物品,一般为电子产品的全球唯一标识码。常用于防伪。最大的特点就是唯一。

序列号就是软件开发商给软件的一个识别码,和人的身份证号码类似,其作用主要是为了防止自己的软件被用户盗用。用户要使用其软件就必须知道序列号。在用户注册或购买产品时生成唯一的识别码,一般称作机器码,也叫认证码、注册申请码等。)

经过多种方法后依然获取不到系统序列号的值,折腾了好几天 都找不到原因 在debug版本可以 但是在user版本不行。

经查询学习过后发现得知是不是DeviceIdentifiersPolicyService的原因 ?

相关修改代码:

public @Nullable String getSerial() throws RemoteException {
// Since this invocation is on the server side a null value is used for the
// callingPackage as the server's package name (typically android) should not be used
// for any device / profile owner checks. The majority of requests for the serial number
// should use the getSerialForPackage method with the calling package specified.
/* if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mContext,
/* callingPackage / null, "getSerial")) {return Build.UNKNOWN;}/
return SystemProperties.get("ro.serialno", Build.UNKNOWN);
}
    @Override
    public @Nullable String getSerialForPackage(String callingPackage) throws RemoteException {
        /*if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mContext,
                callingPackage, "getSerial")) {
            return Build.UNKNOWN;
        }*/
        return SystemProperties.get("ro.serialno", Build.UNKNOWN);
    }
}

学习收获:

学习是人这一生永远离不开的主题,然而学什么、怎样学也始终在拷问着每一位在人生旅途中奋力前行的行进者,本次活动中让我对学习有了新的认识。珍惜CSDN的这个打卡活动,去努力的多学习相关自己感兴趣的知识,通过这个平台去不断的提升自己,这样才能在以后的工作中脱颖而出。只要自己愿意努力,就一定会成功的。