[英]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.