Android使用超级用户权限?允许访问

sg8*_*86- 6 android

我试图找到在Android设备上拥有超级用户访问权限的方法.基本上我希望我的应用程序能够删除系统文件,因此在大多数其他应用程序启动应用程序之后询问用户是否可以,然后我想用什么代码来执行这些操作?无法在谷歌找到很多

提前致谢!

小智 10

如果设备已植根,则可以使用以下代码访问root shell:

    try
    {
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); 
        DataInputStream inputStream = new DataInputStream(process.getInputStream());

        outputStream.writeBytes(command + "\n");
        outputStream.flush();

        outputStream.writeBytes("exit\n"); 
        outputStream.flush(); 
        process.waitFor();
    }
    catch (IOException e)
    {
        throw new Exception(e);
    }
    catch (InterruptedException e)
    {
        throw new Exception(e);
    }
Run Code Online (Sandbox Code Playgroud)

其中"command"是您要执行的命令.