The Power key is usually not obtained by the framework app. 1: Modify the interceptKeyBeforeQueueing method of phoneWindowManager. java, and add the following code after the reference line.
Case KeyEvent. KEYCODE_POWER: {// reference line result & = ~ ACTION_PASS_TO_USER; // reference line // add begin ActivityManager activityManager = (ActivityManager) getSystemService (Context. ACTIVITY_SERVICE); try {if (activityManager. getRunningTasks (1 ). get (0 ). topActivity. getPackageName (). equals (your_special_package_name) {// Please reset the special package name. result | = ACTION_PASS_TO_USER; Xlog. d (TAG, detect power key in special package, pass to user !) } Catch (NullPointerException e) {Xlog. d (TAG, ingore a NullPointerException...);} // add end
Note:The content in the yellow background must be replaced with the package name of the app whose power key is to be processed..
Note:
The content in the yellow background must be replaced with the package name of the app whose power key is to be processed..