Android Question How to detect device is rooted or not programmatically?

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
How can we detect if device is rooted or not programmatically?
Also, how can we force our app to not installed on unrooted devices?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You cannot force your app not to be installed on rooted devices.
He want
our app to not installed on unrooted devices?
He want to limit the app to be installed only on Rooted devices.

But the result - i guess - i the same. It can not be forced this way too.
 
Upvote 0

amidgeha

Active Member
Licensed User
Longtime User
How can we detect if device is rooted or not programmatically?
Also, how can we force our app to not installed on unrooted devices?

You can execute a shell command "su" using the phone library and check the error message if any. In case of no error, this means su command can be reached and the phone is rooted. You can do it in java:
public boolean isPhoneRooted(){
Process process = null;
try{
process = Runtime.getRuntime().exec("su");
return true;
} catch (Exception e) {
return false;
} finally{
if(process != null){
try{
process.destroy();
}catch (Exception e) {
}
}
}
}
 
Upvote 0
Top