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

362 篇文章 3 订阅
129 篇文章 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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值