What is the handling of APP_SWITCH and HOME keys above android5.0
Android5.0 above for APP_SWITCH and HOME key handling is like, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
In the case of android5.0 project development, the HOME key needs to be captured. After searching, the implementation function is as follows:
Add the following functions to framework/base/services/core/java/com/android/server/policy/PhoneWindowManager.java:
Private boolean getTopStackActivity (String fullClassName) {
ActivityManager am = (ActivityManager) mContext.getSystemService (Context.ACTIVITY_SERVICE)
RunningTaskInfo info = am.getRunningTasks (1) .get (0)
If (info = = null | | info.topActivity = = null) {
Log.e (TAG, "Top activity is null, error")
Return false
}
If (fullClassName.equals (info.topActivity.getClassName () {
Log.d (TAG, "Top Activity:" + info.topActivity.getClassName ())
Return true
}
Return false
}
HOME key processing:
Add the above function to the if (keyCode = = KeyEvent.KEYCODE_HOME) of the interceptKeyBeforeDispatching function to capture the HOME key at the application layer.
APP_ switch key processing:
Add the above function to if (keyCode = = KeyEvent.KEYCODE_APP_SWITCH) under else if (keyCode = = KeyEvent.KEYCODE_MENU) of the interceptKeyBeforeDispatching function to capture the APP_ switch key in the application layer.
After reading the above, have you mastered how android5.0 handles APP_SWITCH and HOME keys? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!