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.