前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android获取超级用户权限删除文件

Android获取超级用户权限删除文件

作者头像
提莫队长
发布2019-02-21 11:03:05
1.6K0
发布2019-02-21 11:03:05
举报
文章被收录于专栏:刘晓杰刘晓杰

获取超级用户权限的windows代码如下: 打开命令提示符,进入sdk\platform-tools文件夹,找到adb.exe。然后输入如下代码:

代码语言:javascript
复制
adb.exe shell  
su  
mount -orw,remount rootfs /  
chmod 777 /mnt/shell

这样就可以删除/mnt/shell文件夹下的文件。在Android中,上面的代码可以用如下代码替换

代码语言:javascript
复制
/**
     * 获取系统管理员权限
     * 手机必须要root
     * 
     * @param command
     * @return
     * @throws InterruptedException
     */
    private boolean runRootCommand() throws InterruptedException {
        Process process = null;
        DataOutputStream os = null;
        try {
            Log.i("test", "su");
            process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            Log.i("test", "mount -orw,remount rootfs /");
            os.writeBytes("mount -orw,remount rootfs /" + "\n");
            Log.i("test", "chmod 777 /mnt/shell");
            //可以在这里修改你想要的文件夹的路径
            os.writeBytes("chmod 777 /mnt/shell" + "\n");
            os.writeBytes("exit\n");
            os.flush();
            process.waitFor();
        } catch (Exception e) {
            Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "
                    + e.getMessage());
            return false;
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                process.destroy();
            } catch (Exception e) {
            }
        }
        return true;
    }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年05月24日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档