gpt4 book ai didi

android - 在 Android 6 中,用户 10632 和当前进程都没有 android.permission.READ_PHONE_STATE 错误

转载 作者:行者123 更新时间:2023-12-03 09:09:29 27 4
gpt4 key购买 nike

我正在 Android 6 中开发 Android 应用程序,我的服务中的应用程序需要获取设备 ID(getDeviceId)。我已在 list 文件中设置了 android.permission.READ_PHONE_STATE,但在运行时出现此错误:

neither user 10632 nor current process has android.permission.READ_PHONE_STATE. java.lang.SecurityException:getDeviceId need android.permission.Read_Phone_state

我使用 adb install myapk.apk 安装我的 apk 文件,并且我认为所有应用程序所需的权限都在安装时授予。

最佳答案

您还需要在运行时请求权限。

int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_PHONE_STATE);

If the app has the permission, the method returns PackageManager.PERMISSION_GRANTED, and the app can proceed with the operation. If the app does not have the permission, the method returns PERMISSION_DENIED, and the app has to explicitly ask the user for permission.

如果你没有得到它,你应该请求它

ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_PHONE_STATE},
MY_PERMISSIONS_REQUEST_READ_PHONE_STATE);

关于android - 在 Android 6 中,用户 10632 和当前进程都没有 android.permission.READ_PHONE_STATE 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44001415/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com