允许在Android中读取/写入根文件夹的权限 [英] Permission for reading/writing to the root folder in Android
问题描述
我是否可以/必须在我的应用中声明任何权限,
如果我希望该应用程序能够扫描整个"/"文件夹
(例如说以递归方式搜索所有.txt
文件)?
Are there any permissions I can/must declare in my app,
if I want the app to be able to scan the whole "/" folder
(say to search for all .txt
files e.g. recursively)?
到目前为止(调用File.listFiles
时)我只得到null
不管我尝试什么权限.我想我缺少了一些东西.
I am getting just null
so far (when calling File.listFiles
)
no matter what permissions I try. I guess I am missing something.
推荐答案
除非您root设备,否则无法对非root用户设备的根目录进行任何操作,因为第三方应用程序将正常运行用户,并且没有root权限.
Unless you root your device, it is impossible to do any operations on the root directory on a non-rooted device because a third party app will run as a normal user and won't have the root permissions.
但是,根据 https://developer.android.com/reference/android/Manifest.permission ,android.permission.FACTORY_TEST
可以授予您root权限.
However, according to https://developer.android.com/reference/android/Manifest.permission, android.permission.FACTORY_TEST
can give you the root permission.
在API级别1中添加了FACTORY_TEST
FACTORY_TEST added in API level 1
公共静态最终字符串FACTORY_TEST
public static final String FACTORY_TEST
作为制造商测试应用程序运行,作为 超级用户.仅在设备在制造商中运行时可用 测试模式.
Run as a manufacturer test application, running as the root user. Only available when the device is running in manufacturer test mode.
不供第三方应用程序使用.
Not for use by third-party applications.
常量值:"android.permission.FACTORY_TEST"
Constant Value: "android.permission.FACTORY_TEST"
但是请注意,这只能由制造商通过修改固件来使用,而不适用于任何第三方库或应用程序.
But note this can only be used by manufacturers by modifying the firmware, and this is not for any third part libraries or applications.
这篇关于允许在Android中读取/写入根文件夹的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!