android实现短按电源键关机的实现代码
打开文件:\frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java
在代码:privatestaticfinalintMSG_POWER_LONG_PRESS=14;下面添加:
privatestaticfinalintMSG_POWER_SHUT_DOWN=15;
在:
caseMSG_POWER_LONG_PRESS: powerLongPress(); break;
下面添加:
caseMSG_POWER_SHUT_DOWN: mWindowManagerFuncs.shutdown(false); break;
找到caseKeyEvent.KEYCODE_POWER:
注释掉
/*result&=~ACTION_PASS_TO_USER; isWakeKey=false;//wake-upwillbehandledseparately if(down){ interceptPowerKeyDown(event,interactive); }else{ interceptPowerKeyUp(event,interactive,canceled); } break;*/
再添加:
if(down){ if(mPowerManager.isScreenOn()){ Messagemsg=mHandler.obtainMessage(MSG_POWER_SHUT_DOWN); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); }else{ Log.e("GOtoWakeup-------->TTTEEE","keyCode:"+keyCode); wakeUpFromPowerKey(event.getDownTime()); } } break;
之后在目录frameworks/base/policy中mm编译出android.policy.jarpush到system/framework重启即可
到此这篇关于android实现短按电源键关机的实现代码的文章就介绍到这了,更多相关android短按电源键关机内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!