我试图创建一个应用程序来检查手机是否有根,我已经效仿了一些例子,但仍然无法工作,请任何人帮助我,或者可能提供更多示例。我想知道在最近的版本中是否有更好的方法可以实现它?
import java.io.File;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity {
public boolean isPhoneRooted() {
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("Phone Rooted")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
else{
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("Phone no Rooted")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
} catch (Throwable e1) {
// ignore
}
return false;
}
}