Set custom Launcher as the default application

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.