Android gaining permission to "/data" folder using Roottools?

567 Views Asked by At

I am working on a File manager, and I want to be able to get root access to the /data folder. I want to create and maintain File objects from that directory. How can I accomplish this? Here is what I tried so far..

if (RootTools.isRootAvailable()) {
   File file = new File("/data");
 //here is where the app crashed, and I got a null pointer exception.
} else {
    // do something else
}
1

There are 1 best solutions below

1
On

Rooting lets all user-installed applications run privileged commands typically unavailable to the devices in the stock configuration. Rooting is required for more advanced and potentially dangerous operations including modifying or deleting system files, removing carrier- or manufacturer-installed applications, and low-level access to the hardware itself (rebooting, controlling status lights, or recalibrating touch inputs.) A typical rooting installation also installs the Superuser application, which supervises applications that are granted root or superuser rights.

From Wikipedia

If you are using Roottools, this will be enough:

if (RootTools.isRootAvailable()) {
    // su exists, do something
} else {
    // do something else
}

It's a simple root check, but once you run this code, you will see su prompt(if your device is rooted) and once you grant access to your app you will have the super user rights.

P.S.: You may need to change the /data folder permissions to be writable.