【Android】java.lang.SecurityException: getDeviceId: Neither user 10065 nor current process has android.permission.READ_PHONE_STATE

RT, 异常信息如下:

java.lang.SecurityException: getDeviceId: Neither user 10065 nor current process has android.permission.READ_PHONE_STATE.

PS:
Android Studio 版本:2.3.3
模拟器环境:Genymotion, Android 7.1.1, API 25

原因:动态权限的问题
Android 6.0 (API Level 23) 及以后引入了运行时权限,安装 APP 时不再授予所有需要的权限,而是在运行的时候根据需要向用户请求权限,而且用户可以随时取消已经授予的权限。

推荐开源库:
GitHub 上有个对开源库 https://github.com/googlesamples/easypermissions 进行二次封装的开源库 https://github.com/forJrking/HeiPermission 还不错,可以尝试下。

参考链接:
http://blog.csdn.net/github_33304260/article/details/53328297
https://developer.android.com/training/permissions/requesting.html

原文地址:https://www.cnblogs.com/jaxer/p/7151254.html