Fixed Launcher method in Android system
When developing Android systems, you may encounter such a requirement:
Because it is a self-owned brand, it also involves a service push, so we hope that the Launcher can be fixed, the third party can install, but when you press the Home key, you must return the system default Launcher
After analyzing the Home key process, we can find that it is easy to do. I would like to share with you:
Path: frameworks \ base \ policy \ src \ com \ android \ internal \ policy \ impl \ PhoneWindowManager. java
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);..}
To: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);..}
That is, to add a setComponent condition here, you need to change the ComponentName to what you need.
After verification, it can be done completely