在app开发中 监听home事件也是常有的功能,只是在普通app中,通过onKeyDown很容易监听到Home事件
但是在Launcher首页就监听不到Home事件了 纠结了好久才找到解决方法
所以就参考系统Launcher3的源码来解决这个问题
导航栏home按键触发intent
当我们点击SysytemUI中的导航栏(NavigationBar)中的home按钮(KeyButtonView)时其最终会调用到PhoneWindowManager中的startDockOrHome中,在此方法中会启动符合HomeIntent的页面(其实就是Launcher页面)。
mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
mHomeIntent.addCategory(Intent.CATEGORY_HOME);
mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED