简体   繁体   English

我是否必须声明WRITE_EXTERNAL_STORAGE和READ_EXTERNAL_STORAGE?

[英]Do I have to declare both WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE?

Is it enough to declare <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> or do I also have to declare <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ? 是否足以声明<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />或者我还必须声明<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> The Javadocs omit this important information. Javadocs省略了这些重要信息。

It's best to be explicit and declare both permissions, but declaring only android.permission.WRITE_EXTERNAL_STORAGE will automatically add android.permission.READ_EXTERNAL_STORAGE to your APK at build time. 最好是显式并声明两个权限,但只声明android.permission.WRITE_EXTERNAL_STORAGE将在构建时自动将android.permission.READ_EXTERNAL_STORAGE添加到您的APK。

You can use the command aapt dump badging on an APK to see that Android considers usage of the write permission to imply that you also want read permission. 您可以在APK上使用命令aapt dump badging以查看Android是否考虑使用写入权限来暗示您还需要读取权限。

Here's some output from aapt for an APK of mine where I declared only WRITE_EXTERNAL_STORAGE in my manifest: 这是我的一个APK的aapt的一些输出,我在我的清单中声明 WRITE_EXTERNAL_STORAGE

uses-permission:'android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission:'android.permission.READ_EXTERNAL_STORAGE'
uses-implied-permission:'android.permission.READ_EXTERNAL_STORAGE',
  'requested WRITE_EXTERNAL_STORAGE'

READ_EXTERNAL_STORAGE only exists as of Jelly Bean (Level 16). READ_EXTERNAL_STORAGE仅存在于Jelly Bean(级别16)。 According to the docs , all applications as of Jelly Bean have that permission, even without declaring it: 根据文档 ,Jelly Bean的所有应用程序都有这种许可,即使没有声明:

Provides protected read access to external storage. 提供对外部存储的受保护读访问。 In Android 4.1 by default all applications still have read access. 在Android 4.1中,默认情况下所有应用程序仍具有读取权限。 This will be changed in a future release to require that applications explicitly request read access using this permission. 这将在将来的版本中进行更改,以要求应用程序使用此权限明确请求读取访问权限。 If your application already requests write access, it will automatically get read access as well. 如果您的应用程序已经请求写访问权限,它也将自动获得读取权限。 There is a new developer option to turn on read access restriction, for developers to test their applications against how Android will behave in the future. 有一个新的开发人员选项可以打开读取访问限制,开发人员可以根据Android将来的行为来测试他们的应用程序。

So, you should declare it for future compatibility, but this might not be the source of your problem, unless you're using a Jelly Bean phone and set the developer option "Protect USB storage" option. 因此,您应该声明它以便将来兼容,但这可能不是您的问题的根源,除非您使用Jelly Bean手机并设置开发人员选项“保护USB存储”选项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么应用程序同时需要READ_EXTERNAL_STORAGE和WRITE_EXTERNAL_STORAGE权限才能解码位图? - Why app needs both READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions to decode bitmap? Play 安装引用库添加 WRITE_EXTERNAL_STORAGE 和 READ_EXTERNAL_STORAGE 权限 - Play Install Referrer Library Adding WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions 从 Android 项目中删除 WRITE_EXTERNAL_STORAGE 和 READ_EXTERNAL_STORAGE 权限 - Remove WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions from Android Project 我是否需要在Android 4.1及更低版本上明确声明WRITE_EXTERNAL_STORAGE权限? - Do I need to explicitly declare WRITE_EXTERNAL_STORAGE permission on Android 4.1 and earlier? READ_EXTERNAL_STORAGE 显示权限,但不显示 READ_EXTERNAL_STORAGE - READ_EXTERNAL_STORAGE shows permission but not READ_EXTERNAL_STORAGE 在检查文件夹是否存在或列出其子文件夹之前,我是否必须检查 READ_EXTERNAL_STORAGE - Do I have to check READ_EXTERNAL_STORAGE before checking if folder exists or listing its subfolders 在解压 obb 文件之前是否必须检查 READ_EXTERNAL_STORAGE? - Do I have to check READ_EXTERNAL_STORAGE before unzip obb file? 清单中的WRITE_EXTERNAL_STORAGE - WRITE_EXTERNAL_STORAGE in Manifest WRITE_EXTERNAL_STORAGE权限 - WRITE_EXTERNAL_STORAGE Permission 是否可以在没有Android v6.0的WRITE_EXTERNAL_STORAGE或READ_EXTERNAL_STORAGE权限的情况下从相机捕获图像并从图库中选取图片? - Is it possible to capture image from Camera and pick from Gallery without WRITE_EXTERNAL_STORAGE or READ_EXTERNAL_STORAGE permission in Android v6.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM