how to get access of android root directory (/system/app) programatically?

 ̄綄美尐妖づ 提交于 2019-12-03 21:45:29

Refer the below code to move user app apk into system app apk in rooting device with the help of RootTools method .

     PackageInfo paramPackageInfo = null;
        try {
            paramPackageInfo = this.getPackageManager().getPackageInfo(
                    this.getPackageName(), 0);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }

        ApplicationInfo localApplicationInfo = paramPackageInfo.applicationInfo;

String str1 = "/system/app/" + localApplicationInfo.packageName
                + ".apk";
        String str2 = "busybox mv " + localApplicationInfo.sourceDir + " "
                + str1;

        RootTools.remount("/system", "rw");
        RootTools.remount("/mnt", "rw");

        CommandCapture command = new CommandCapture(0, str2,
                "busybox chmod 644 " + str1);

        try {
            RootTools.getShell(true).add(command).waitForFinish();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        } catch (RootDeniedException e) {
            e.printStackTrace();
        }

        RootTools.remount("/system", "ro");
        RootTools.remount("/mnt", "ro");

Necessary of Busybox and superuser app while use the above code in your application.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!