通常情况下,安卓平台下的移动端大多都是长按关机,但是最近客户要求旋转按钮(对讲机)关机,于是我就以为相当于短按关机,直接调用了 mWindowManagerFuncs.shutdown(true) 结果不是关机 而是重启,打了很多log也不知道原因,因为并没有进入到和reboot有关的方法里面去,用 cat sys/class/BOOT/BOOT/boot/boot_mode 抓取开机原因,也是正常的,折腾了两天,试过反射,handler,异步任务,都关不了机,在网上查了资料,参考https://blog.youkuaiyun.com/luzhenrong45/article/details/42092007
case KeyEvent.KEYCODE_POWER:{
//mWindowManagerFuncs.shutdown(true)
if (!down){
if (!isWakeKey) {
wakeUpFromPowerKey(event.getEventTime());
}
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
//Where false is replaced by true, a confirmation window will pop up whether to shut down
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
mContext.startActivity(intent);
}
终于关机了
刚入framwork开发的坑,如果有大神知道直接调用mWindowManagerFuncs.shutdown(true)关不了机的原因,请告诉我一声