Example of home key listening and interception in Android

First of all, you should understand a situation first, that is, Android cannot intercept the home key in applications. Today we take you to see three cases of the home key.

1. Logical processing of pressing home key in application

When we press the home key in the application, the interface will start to the desktop. We can see its implementation principle in the frameworks \ base \ policy \ SRC \ com \ Android \ internal \ policy \ impl \ phonewindowmanager.java class, which is nothing more than calling the following code.

Create an intent that starts to the desktop.

2. Listen for home key in application

In Android applications, if you want to listen to the home key, you can use the broadcast mechanism, which is also reflected in the source code.

In this way, you can monitor whether home is pressed.

3. Block the home key in the frameworks layer

In the frameworks \ base \ policy \ SRC \ com \ Android \ internal \ policy \ impl \ phonewindowmanager.java file, let's first look at the interceptkeybeforedispatching () method.

Enter the launchhomefromhotkey method.

The above method can handle the interception of the home key. Next, we enter the startdockorhome method.

Well, here is a simple monitoring and interception of the home key.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>