简体   繁体   English

如何获得Android应用程序的根访问权限?

[英]How to get Root Access for android app?

I am working on an android app, and I want the user to be able to access the data directory. 我正在开发一个android应用,我希望用户能够访问数据目录。 I know you can do, Runtime.getRuntime().exec("su"); 我知道您可以做到, Runtime.getRuntime().exec("su"); , but I tried that and it opens up the screen that asks if you want to get permission, but it does not allow me to retrieve the directory after words. ,但我尝试过该操作,它打开了询问您是否要获得许可的屏幕,但是它不允许我在输入文字后检索目录。 Here is the code: 这是代码:

try {
                Runtime.getRuntime().exec("su");
                final File dataFile = Environment.getDataDirectory();
                FileAdapter adapter = new FileAdapter(getActivity());
                adapter.setFiles(dataFile.listFiles());
                setListAdapter(adapter);
                setListShown(true);
            } catch (IOException e) {
                Toast.makeText(getActivity(),"Sorry, Root access was denied",Toast.LENGTH_LONG).show();
            }

The Runtime.exec() documentations says Executes the specified program in a separate native process. Runtime.exec()文档说Executes the specified program in a separate native process. Which means that, its the new process that gets the root access. 这意味着,它是获得根访问权限的新过程。 I think you have to use the Process object that is returned by the exec() and open output stream and execute the remaining commands that accomplishes your job. 我认为您必须使用exec()返回的Process对象并打开输出流,并执行完成任务的其余命令。 You can refer to Root Tools source code for more info on how to do that. 您可以参考Root Tools源代码以获取有关如何执行此操作的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM