采用Android超级用户权限?允许访问 [英] Android using Super User Permissions ? allowing access

查看:434
本文介绍了采用Android超级用户权限?允许访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试找到其背后的And​​r​​oid设备上的超级用户访问权限的方法。基本上,我想我的应用程序能够删除系统文件等,询问用户是否其确定后,该应用程序是像大多数其他应用程序,以及c $ C我究竟在寻找什么$用于执行这类行动启动?无法找到很多关于谷歌

im trying to find the method behind having superuser access on android devices. basically i want my app to be able to remove system files, and so asking the user if its ok after the app is launched like most other apps, and then what code exactly am i looking to use to perform these sorts of actions? cant find much on google

在此先感谢!

推荐答案

如果该设备是植根,你可以使用下面的code,以获得一个root shell:

If the device is rooted, you can use the following code to gain access to a 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);
    }

在哪里命令是要执行的命令。

Where "command" is the command that you want to execute.

这篇关于采用Android超级用户权限?允许访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆