当前位置: 代码迷 >> 综合 >> Home key点亮屏幕后, 使手机不自动回到 launcher 界面
  详细解决方案

Home key点亮屏幕后, 使手机不自动回到 launcher 界面

热度:32   发布时间:2024-01-19 17:51:43.0
1: 修改 phonewindowmanager.java 中 interceptKeyBeforeQueueing 方法的下面这段 code:
if (keyCode == KeyEvent.KEYCODE_POWER) {
            policyFlags |= WindowManagerPolicy.FLAG_WAKE;
        }
改为:
if (keyCode == KeyEvent.KEYCODE_POWER || (keyCode == KeyEvent.KEYCODE_HOME && !isScreenOn)) {
            policyFlags |= WindowManagerPolicy.FLAG_WAKE;
}
 
2: 仍然是此方法,对应部分修改为如下:
        int result; //参考行
  
        if (((isScreenOn && !mHeadless) || (isInjected && !isWakeKey))) {//参考行
            // When the screen is on or if the key is injected pass the key to the application.
            Log.d(TAG,"oldScreenOn = "+oldScreenOn); 
            if(!oldScreenOn && (keyCode == KeyEvent.KEYCODE_HOME)){  
                Log.d(TAG,"eat the home up because home down has dropped");
                result |= ACTION_WAKE_UP;
            }else{

                result = ACTION_PASS_TO_USER;
            }
        } else {
            // When the screen is off and the key is not injected, determine whether
            // to wake the device but don't pass the key to the application.
            result = 0;
            if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
                if (keyguardActive) {
                    // If the keyguard is showing, let it wake the device when ready.
                    mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
                } else {
                    // Otherwise, wake the device ourselves.
                    result |= ACTION_WAKE_UP;
                }
            }
        }

        oldScreenOn = isScreenOn;
 
其中的 oldScreenOn 请定义在 phoneWindowManager 这个 class 中, 如下:
boolean oldScreenOn = true;
  相关解决方案