在android App中怎样实现对设备重启或者关机功能

来源:互联网 发布:雅思听力怎么提高 知乎 编辑:程序博客网 时间:2024/04/30 21:12
重启://发送广播
    Intent reboot = new Intent(Intent.ACTION_REBOOT);
    reboot.putExtra("nowait",1);
    reboot.putExtra("interval",1);
    reboot.putExtra("window",0);
    sendBroadcast(reboot);
   
    关机://启动 Activity
    Intent shutdown = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
    shutdown.putExtra(Intent.EXTRA_KEY_CONFIRM,showShutdownDialog);
    shotdown.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(shutdown);
原创粉丝点击