Root access with java.io.file on Android

Viewed 2140

I am trying to create a root file browser, however, I have some problems accessing root directories. When I try to access /data, the folder is empty.

When I do this:

File file = new File("/data/");

And then request for the items in that directory, it's empty. (No root access). I know how to execute simple root commands by using a Process, but then it won't work on phones without root. So I need something that will work on all phones.

I thought about using File for unrooted devices and the command ls for rooted devices, but don't know if that's the best solution. I could also just use ls with or without root, but I'd like to use File.

Is there a way to make a root file browser, while also keeping support for non-rooted phones?

Thanks

1 Answers
Related