我想,当我按下button.For,我使用android2.3.3为开发这个应用程序在emulator.I'm写这些..重新启动android手机(模拟器)?
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);
}
}
});
}
这不是工作重新启动手机。 按下按钮后,它不会发生任何错误,也不会发生任何事情。 烤面包片被显示的结果1
之后,我尝试这种代码也..
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("reboot"+"\n");
os.writeBytes("exit\n");
os.flush();
同result.I添加有任何想法,必要的权限also.Is人吗?
[不知怎的,我要重新启动(或关闭)手机上按后按A钮。]
我认为设备需要拥有root权限...... –