Set custom Launcher as the default application
Core code:
.... // Configure String action = Intent in xml contained in the launcher application. ACTION_MAIN; String category1 = Intent. CATEGORY_HOME; String category2 = Intent. CATEGORY_DEFAULT; IntentFilter filter = new IntentFilter (); filter. addAction (action); filter. addCategory (category1); filter. addCategory (category2); // create the Default Application componentName. Here, this application ComponentName component = new ComponentName (getApplicationContext (). getPackageName (), MainActivity. class. getName (); Intent intent = new Intent (); intent. setAction (action); intent. addCategory (category1); PackageManager pm = getPackageManager (); // use PackageManager to find that action is Intent. ACTION_MAIN and category are Intent. list of all application packages of CATEGORY_HOME
List = pm. queryIntentActivities (intent, PackageManager. GET_INTENT_FILTERS); ComponentName [] comNames = new ComponentName [list. size ()]; int size = list. size (); for (int I = 0; I <size; I ++) {ActivityInfo activityInfo = list. get (I ). activityInfo; String pckName = activityInfo. packageName; String clsName = activityInfo. name; // clear the original default application setting pm cyclically. clearPackagePreferredActivities (pckName); ComponentName cn = new ComponentName (pckName, clsName); comNames [I] = cn;}/** sets the default application and analyzes the Huawei Link + source code, the final Setting Parameter persists to/data/system/users/0/package-restrictions.xml ** addPreferredActivity requires android. permission. SET_PREFERRED_APPLICATIONS permission. The permission must be signed using signapk */pm. addPreferredActivity (filter, IntentFilter. MATCH_CATEGORY_EMPTY, comNames, component );...
For more information about signapk signature, see
How to obtain system permissions for Android apk