MediaStore.Images.Media.insertImage throwing permission denial on some devices

泄露秘密 提交于 2019-11-30 20:53:05

Quoting developers.android.com:

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.

System permissions are divided into two categories, normal and dangerous:

  • Normal permissions do not directly risk the user's privacy. If your app lists a normal permission in its manifest, the system grants the permission automatically.

  • Dangerous permissions can give the app access to the user's confidential data. If your app lists a normal permission in its manifest, the system grants the permission automatically. If you list a dangerous permission, the user has to explicitly give approval to your app.

READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE are in the Dangerous category, for this reason when targetSdkVersion is 23 or higher you need to request the permission directly to the user when the app is running.

Nothing has changed for device with API level lower than 23, this is why you don't have any issue with Nexus 4.

You can find more information on how to check and request a permission here: https://developer.android.com/training/permissions/requesting.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!