SecurityException与android.permission.xxxx
1 | java.lang.SecurityException |
这个问题是由于android6.0的动态权限引起的
首先看下google怎么说的
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app’s functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app’s Settings screen.
从6.0起,权限分成两类,一个是普通权限,一个是危险权限
- 普通权限就是手机本身的权限,跟以前一样在AndroidManifest.xml里面申请就可以了
- 危险权限就是需要获取用户信息的一些权限,比如
在activity里面,加入这俩方法
1 | public void getPermission(){ |
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 七夜的小屋!