How to create android apps with root access?

前端 未结 5 1418
一个人的身影
一个人的身影 2020-12-07 21:10

I found out that there\'s so many apps out there which required root access.

How were they able to create those apps? Where did they found all the resource? Is ther

相关标签:
5条回答
  • 2020-12-07 21:38

    Usually rooted apps are just using commands like "su ...", which they aren't able to use without root access. And with these command executions can they reach everything (i.e. removing a system app or boosting your android device)

    0 讨论(0)
  • 2020-12-07 21:39

    You need su installed in the phone (of course). Details here: http://forum.xda-developers.com/showthread.php?t=682828

    And to use it, is as simple as running su command. Here is a sample I use to reboot the phone programmatically (copied from this answer: Android 2.2: Reboot device programmatically )

    try {
        Runtime.getRuntime().exec("su");
        Runtime.getRuntime().exec("reboot");
    } catch (IOException e) {
    } 
    
    0 讨论(0)
  • 2020-12-07 21:39

    Many of the applications depend on a shell script/command prefixed with su.

    I do not think there is a way to request another context or elevate privileges in Android API.

    0 讨论(0)
  • 2020-12-07 21:42

    Use this function and use it anywhere of your project

     public static void sudo(String... strings) {
        try {
            Process su = Runtime.getRuntime().exec("su");
            DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
    
            for (String s : strings) {
                outputStream.writeBytes(s + "\n");
                outputStream.flush();
            }
    
            outputStream.writeBytes("exit\n");
            outputStream.flush();
            try {
                su.waitFor();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    Usage of the above function and use it any type of shell commands with root users

      sudo("iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080");
    
    0 讨论(0)
  • 2020-12-07 21:49

    Should work on most versions:

    try {
        Runtime.getRuntime().exec("su -c reboot");
    } catch (IOException e) {
    } 
    
    0 讨论(0)
提交回复
热议问题