Getting Android's root privileges is simple, as long as you execute the command "SU" under Runtime.
Copy Code code as follows:
Get root Permissions
public void Get_root () {
if (Is_root ()) {
Toast.maketext (Mctx, "already has root privileges!", Toast.length_long). Show ();
}
else{
try{
Progress_dialog = Progressdialog.show (Mctx,
"Root", "Getting root permission ...", true, false);
Runtime.getruntime (). EXEC ("su");
}
catch (Exception e) {
Toast.maketext (mctx, "Error getting root permission!", Toast.length_long). Show ();
}
}
}
where Is_root () determines whether the root permission is already in existence. As long as one of the two files in/system/bin/su,/system/xbin/su, indicates that you already have root permissions, and if two do not exist, you do not have root permissions.
Copy Code code as follows:
Determining whether to have root permissions
public static Boolean Is_root () {
Boolean res = false;
try{
if ((!new File ("/system/bin/su"). Exists ()) &&
(!new File ("/system/xbin/su"). Exists ())) {
res = false;
}
else {
res = true;
};
}
catch (Exception e) {
}
return res;