废话少说,直接上代码:
public void rebootAction(){
new AlertDialog.Builder(this)
.setTitle("Warning")
.setMessage("Sure to reboot?")
.setNegativeButton("Cancel", null)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String cmd = "su -c reboot";
try {
Runtime.getRuntime().exec(cmd);
} catch (Exception e){
Toast.makeText(getApplicationContext(), "Error! Fail to reboot.", Toast.LENGTH_SHORT).show();
}
}
})
.show();
}
还有一种