简体   繁体   English

读取/写入Android中根文件夹的权限

[英]Permission for reading/writing to the root folder in Android

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 eg recursively)? (比如搜索所有.txt文件,例如递归)?

I am getting just null so far (when calling File.listFiles )到目前为止,我得到的只是null (调用File.listFiles
no matter what permissions I try.无论我尝试什么权限。 I guess I am missing something.我想我错过了一些东西。

Are there any permissions I can/must declare in my app?我可以/必须在我的应用程序中声明任何权限吗?

No. In order to access the root (/) folder your app must have a root permission which a user app can't have.不可以。为了访问根 (/) 文件夹,您的应用程序必须具有用户应用程序不能拥有的根权限。

If your device is rooted, you can try to elevate the root rights from within the app which isn't a trivial task.如果您的设备已植根,您可以尝试从应用程序内提升 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.除非你root你的设备,否则无法在非root设备上对根目录进行任何操作,因为第三方应用程序将以普通用户身份运行并且没有root权限。

However, according to https://developer.android.com/reference/android/Manifest.permission , android.permission.FACTORY_TEST can give you the root permission.但是,根据https://developer.android.com/reference/android/Manifest.permissionandroid.permission.FACTORY_TEST可以给你root权限。

FACTORY_TEST added in API level 1在 API 级别 1 中添加了 FACTORY_TEST

public static final String FACTORY_TEST public static final String FACTORY_TEST

Run as a manufacturer test application, running as the root user.作为制造商测试应用程序运行,以 root 用户身份运行。 Only available when the device is running in manufacturer test mode.仅当设备在制造商测试模式下运行时可用。

Not for use by third-party applications.不供第三方应用程序使用。

Constant Value: "android.permission.FACTORY_TEST"常量值:“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.但请注意,这只能由制造商通过修改固件使用,不适用于任何第三方库或应用程序。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM