分类: Android平台
2014-12-03 14:40:59
在做Android系统的开发时,有时候会碰到一个这样的需求:
因为是自主品牌,也涉及到一个服务在推送,所以希望Launcher能固定会一下,第三方的可以安装 ,但是按Home键时,必须返回系统默认的Launcher
经过分析Home键的流程,发现可以很简单的办到,现和大家分享一下:
路径:frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java
[java] view plaincopy在CODE上查看代码片派生到我的代码片
public void init(Context context, IWindowManager windowManager,WindowManagerFuncs windowManagerFuncs) {....
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);
..}
修改为:
[java] view plaincopy在CODE上查看代码片派生到我的代码片
public void init(Context context, IWindowManager windowManager,
WindowManagerFuncs windowManagerFuncs) {....
ComponentName mHomecom = new ComponentName("com.android.launcher3", "com.android.launcher3.Launcher");
mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
mHomeIntent.addCategory(Intent.CATEGORY_HOME);
mHomeIntent.setComponent(mHomecom);
mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
..}
也就是在此中增加一个setComponent的条件,ComponentName需要改成你所需要的就可以了。
经验证,完全可以搞定
更多精彩文章请浏览