Android系统应用开发(七)屏蔽Home键和屏幕的唤醒和休眠,AlarmManager

本文介绍了如何在Android系统应用中屏蔽Home键,以及如何控制屏幕的休眠和唤醒。通过修改源码实现Home键拦截,并详细讲解了AlarmManager的使用,包括设置一次性闹钟、重复闹钟及其参数含义,以及如何创建PendingIntent。
摘要由CSDN通过智能技术生成

基于android4.4

一、屏幕的HOME键

做了一个锁屏app替换系统的app ,但是在应用层是无法屏蔽home键的,找了资料,改了源码,终于解决

代码位置
frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java下的 

定位到名为interceptKeyBeforeDispatching 的函数 



从函数名我们可以知道此函数是是在分发按键消息之前进行拦截。
查看对KEYCODE_HOME home键的处理 

  // First we always handle the home key here, so applications
        // can never break it, although if keyguard is on, we do let
        // it handle it, because that gives us the correct 5 second
        // timeout.
        if (keyCode == KeyEvent.KEYCODE_HOME) {


            // If we have released the home key, and didn't do anything else
            // while it was pressed, then it is time to go home!
            if (!down) {
                cancelPreloadRecentApps();


                mHomePressed = false;
                if (mHomeConsumed) {
                    mHomeConsumed = false;
                    return -1;
                }


                if (canceled) {
                    Log.i(TAG, "Ignoring HOME; event canceled.");
                    return -1;
                }


                // If an incoming call is ringing, HOME is totally disabled.
                // (The user is already on the InCallScreen at this point,
                // and his ONLY options are to answer or reject the call.)
                try {
                    ITelephony telephonyService = getTelephonyService();
                    if (telephonyService != null && telephonyService.isRinging()) {
                        Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
                        return -1;
                    }
                } catch (RemoteException ex) {
                    Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
                }


                // Delay handling home if a double-tap is possible.
                if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
                    mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
                    mHomeDoubleTapPending = true;
                    mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
                            ViewConfigurati
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值