android實現短按電源鍵關機的實現程式碼
阿新 • • 發佈:2020-11-10
開啟檔案:\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 短按電源鍵關機內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!