且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MediaStore.Images.Media.insertImage 在某些设备上抛出权限拒绝

更新时间:2022-11-16 23:26:07

引用 developers.android.com:

从 Android 6.0(API 级别 23)开始,用户授予以下权限应用程序运行时的应用程序,而不是安装应用程序时.这方法简化了应用程序安装过程,因为用户没有需要在安装或更新应用程序时授予权限.它也是让用户更好地控制应用程序的功能;例如,用户可以选择授予相机应用访问相机的权限,但不能到设备位置.用户可以随时撤销权限时间,转到应用的设置屏幕.

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_STORAGEWRITE_EXTERNAL_STORAGE 属于危险类别,因此当 targetSdkVersion 为 23 或更高时,您需要直接请求权限应用程序运行时的用户.

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.

API 级别低于 23 的设备没有任何变化,这就是为什么您在使用 Nexus 4 时没有任何问题.

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

您可以在此处找到有关如何检查和请求许可的更多信息:https://developer.android.com/training/permissions/requesting.html

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