android實(shí)現(xiàn)短按電源鍵關(guān)機(jī)的實(shí)現(xiàn)代碼
打開文件:frameworksbasepolicysrccomandroidinternalpolicyimplPhoneWindowManager.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重啟即可
到此這篇關(guān)于android實(shí)現(xiàn)短按電源鍵關(guān)機(jī)的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)android 短按電源鍵關(guān)機(jī)內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. NetCore 配置Swagger的詳細(xì)代碼2. 一文秒懂idea的git插件跟翻譯插件3. 使用Blazor框架實(shí)現(xiàn)在前端瀏覽器中導(dǎo)入和導(dǎo)出Excel4. 關(guān)于HTML5的img標(biāo)簽5. IDEA 中創(chuàng)建Spring Data Jpa 項(xiàng)目的示例代碼6. CSS 使用Sprites技術(shù)實(shí)現(xiàn)圓角效果7. 解決request.getParameter取值后的if判斷為NULL的問題8. 前端從瀏覽器的渲染到性能優(yōu)化9. 在 XSL/XSLT 中實(shí)現(xiàn)隨機(jī)排序10. .NET 實(shí)現(xiàn)啟動時重定向程序運(yùn)行路徑及 Windows 服務(wù)運(yùn)行模式部署的方法
