How to delete the root application / application / files?

My phone is rooted. I am trying to make a very simple program. The program should delete the file from the application / application folder. How can i do this? I am new, so the sample code is being evaluated.

+4
source share
3 answers

If your phone is rooted, you can issue commands with root privileges via su - provided that there is a su binary file and your PATH - since Android is a Linux variant. Just execute the delete commands with Runtime.exec() , and Superuser should take care of the permission prompt.

Here is a simple example of its use. I took from this question :

 process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); 
+3
source

You can delete all files inside a folder recursively using the method below.

 private void DeleteRecursive(File fileOrDirectory) { if (fileOrDirectory.isDirectory()) for (File child : fileOrDirectory.listFiles()) { child.delete(); DeleteRecursive(child); } fileOrDirectory.delete(); } 
+1
source

On its github, Chainfire provides an example implementation of the Shell class, which can be used to execute the rm command as root. The rm command is a Linux variant for deleting files (and folders).

Code snippet:

 if(Shell.SU.available()){ Shell.SU.run("rm /data/app/app.folder.here/fileToDelete.xml"); //Delete command else{ System.out.println("su not found"); 

Or, if you are certain that the su binary is available, you can simply run the delete command (comment line) and skip the check

Source: How-To SU

+1
source

Source: https://habr.com/ru/post/1447427/


All Articles