I have android device with root and i try to implement some small app. This app need to read files from /proc/pid/net . I made it with Runtime.getRuntime().exec(new String[] { "su", "-c", "cat /proc/"+PID+ "/net/tcp6" });
but I must accept su -permission for each pid. There are some other possibilities how i can to read system files in android from my app? Something with FileReader? How can I get the su-permissions without exec -commando?
1 Answers
The exec
command IS how you get su
permissions. You might be able to chmod 777
the files you want and then they can likely be read via java. That, or you could move the files you want to read to the sdcard, or your apps data location and read them from there. Here is something very useful for root. You won't have to manually use the exec
command each time, but RootTools
does still use exec
.
I believe if you do something like:
Process p = Runtime.getRuntime().exec("su");
you will get the root access.
And then you can do just:
p.getRuntime().exec("command");
and then you won't have to put the su
in as long as that process is still active.
Though, I haven't done what I explained above (with the process) in quite some time, so I may be wrong. You may still have to include su
each time. But either way, I'd recommend using RootTools
.

- 14,703
- 8
- 66
- 110
-
great i will try RootTools. The second thing will not work, because each time you use `getRuntime().exec` it will be a new instance of terminal open and so for the second time it will have no su-permissions – Aprel Mar 29 '12 at 08:50
-
Okay. I thought that might be the case, but was not sure, so thought I'd suggest anyway. – Reed Mar 29 '12 at 09:10
-
@Aprel I'd forgotten the proper way. If you go to [this question](http://stackoverflow.com/questions/7129144/mount-r-w-system-in-android-application-to-edit-read-only-files/8160400) you can see the proper way of using root access. – Reed Apr 14 '12 at 05:02