I want to restart the mobile when I press a button.For that i wrote these..
PowerManager pm;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
Button test = (Button) findViewById(R.id.button1);
test.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
Process proc = Runtime.getRuntime().exec(new String[] {"su", "-c", "reboot" });
int result = proc.waitFor();
Toast.makeText(ForTestActivity.this, "INt:"+result, Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
Log.i("XXXXXXXXXXXX", "Could not reboot", ex);
}
}
});
}
This is not working in emulator.I'm using android2.3.3 for develop this application. It does not give any errors and nothing happened after I press the button. The toast was displaying result as 1.
After that I tried this code also..
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("reboot"+"\n");
os.writeBytes("exit\n");
os.flush();
Same result.I added necessary permissions also.Is someone having any idea ?
[Somehow I want to restart (or Shutdown) the phone after press a button.]