android实现短按电源键关机的实现代码
打开文件:\frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java
在代码: private static final int MSG_POWER_LONG_PRESS = 14;
下面添加:
private static final int MSG_POWER_SHUT_DOWN=15;
在:
case MSG_POWER_LONG_PRESS: powerLongPress(); break;
下面添加:
case MSG_POWER_SHUT_DOWN: mWindowManagerFuncs.shutdown(false); break;
找到 case KeyEvent.KEYCODE_POWER:
注释掉
/*result &= ~ACTION_PASS_TO_USER; isWakeKey = false; // wake-up will be handled separately if (down) { interceptPowerKeyDown(event, interactive); } else { interceptPowerKeyUp(event, interactive, canceled); } break;*/
再添加:
if(down){ if(mPowerManager.isScreenOn()) { Message msg = mHandler.obtainMessage(MSG_POWER_SHUT_DOWN); msg.setAsynchronous(true); mHandler.sendMessageDelayed(msg, ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); } else { Log.e("GO to Wakeup--------> TTTEEE","keyCode :"+keyCode); wakeUpFromPowerKey(event.getDownTime()); } } break;
之后在目录frameworks/base/policy中mm编译出android.policy.jar push到system/framework重启即可
到此这篇关于android实现短按电源键关机的实现代码的文章就介绍到这了,更多相关android 短按电源键关机内容请搜索海外IDC网以前的文章或继续浏览下面的相关文章希望大家以后多多支持海外IDC网!
【来源:自由互联、日本站群服务器】