简体   繁体   中英

How to acquire root access using shell script in Java code?

I can get root access to phone using 'adb root' in my PC then change a file content under /data folder. Now I want to do it in a apk using Java code. I tried blow code:

Runtime.getRuntime().exec(new String[]{"sh", "/sdcard/my.sh"});

This function works well when shell command do not need a root permission. Now I change my.sh into

su root
chmod 777 /data/filetochange.xml
rm -r /data/filetochange.xml

But it didn't work. Can I do this in Java code?

I think your app need have root permission. You can try to add a line 'android:sharedUserId="android.uid.system"' to AndroidManifest.xml, which property can get system permission. But this is not enough, you need to do other steps and you can google it, there are many detailed tutorials online.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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