Il rilevamento di rooting è un gioco di gatto e topo ed è difficile effettuare il rilevamento di rooting che funzionerà su tutti i dispositivi in tutti i casi.
Se hai ancora bisogno di un po 'di base radicamento rilevamento controllare il codice qui sotto:
/**
* Checks if the device is rooted.
*
* @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
*/
public static boolean isRooted() {
// get from build info
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
} catch (Exception e1) {
// ignore
}
// try executing commands
return canExecuteCommand("/system/xbin/which su")
|| canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
}
// executes a command on the system
private static boolean canExecuteCommand(String command) {
boolean executedSuccesfully;
try {
Runtime.getRuntime().exec(command);
executedSuccesfully = true;
} catch (Exception e) {
executedSuccesfully = false;
}
return executedSuccesfully;
}
Probabilmente non sempre corretto. Testato su ~ 10 dispositivi nel 2014.
Vuoi dire che hai messo radici con uno strumento specifico che aggiunge Superuser.apk? Non esiste un modo programmatico garantito per determinare se un dispositivo è radicato poiché la maggior parte dei controlli potrebbe essere elusa. – dljava
Ho usato questo controllo nel mio prodotto, ma recentemente il Nexus 7.1 sta segnalando false per tutte queste (nessun comando 'which' installato) e SuperSu non si sta installando nella cartella/system/app. – Graeme
Forse dovresti dare un'occhiata a http://stackoverflow.com/questions/1101380/determine-if-running-on-a-rooted-device –