当前位置 : 主页 > 手机开发 > android >

重启Android设备onClick事件的Button

来源:互联网 收集:自由互联 发布时间:2021-06-11
我想重新启动我试过的手机 try { Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" }); proc.waitFor();} catch (Exception ex) { Log.i(TAG, "Could not reboot", ex);} 而且PowerManager看到我的编码,但设
我想重新启动我试过的手机

try {
    Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
    proc.waitFor();
} catch (Exception ex) {
    Log.i(TAG, "Could not reboot", ex);
}

而且PowerManager看到我的编码,但设备没有重新启动,在编码中请给出工作代码

ok = (Button)findViewById(R.id.button1);
    final PowerManager power = (PowerManager)getSystemService(Context.POWER_SERVICE);

    ok.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            power.reboot("fav");
        }
    });

You cannot do a reboot from an ordinary SDK application. Only
applications signed with the system firmware signing key can do this.

复制了这个答案,Programmatically switching off Android phone

网友评论