我想在按下按钮时重新启动移动。 为此我写了这些...
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.
之后我也尝试了这个代码...
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("reboot"+"
");
os.writeBytes("exit
");
os.flush();
同样的结果。 我也添加了必要的权限。 有人知道吗?
[在按下按钮后,我想重新启动(或关闭)电话。 ]