5

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)?

I am getting just null so far (when calling File.listFiles)
no matter what permissions I try. I guess I am missing something.

peter.petrov
  • 38,363
  • 16
  • 94
  • 159
  • 1
    If the .txt files are stored publicly on the sdcard, then you can have access to them with sdcard read access permission. Otherwise, like Onik said, the answer is no unless the device is rooted and you ask for root permission. – Stephan Branczyk Sep 07 '18 at 01:02
  • OK, thanks everyone for their answers. – peter.petrov Sep 07 '18 at 07:44

2 Answers2

3

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.

Onik
  • 19,396
  • 14
  • 68
  • 91
3

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.

However, according to https://developer.android.com/reference/android/Manifest.permission, android.permission.FACTORY_TEST can give you the root permission.

FACTORY_TEST added in API level 1

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.

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.

Community
  • 1
  • 1
shizhen
  • 12,251
  • 9
  • 52
  • 88