How to set the system to automatically enter the default Launch when the system has multiple Launcher

Source: Internet
Author: User
How to set the system to automatically enter the default Launcher when the system has multiple Launcher

[FAQ] How do I set the system to automatically enter the default Launcher when the system has multiple Launcher instances?
[DESCRIPTION]
When the system has multiple launchers, after the system is started and unlocked, a selection box is displayed to allow users to select
If you do not want to select a Launcher, You Want To directly enter a default Launcher and
Choose Settings> Application> Manage Application> list of all applications, and find the previously set
If the default value is canceled, the Launcher selection box is displayed again.
[SOLUTION]
The following uses setting Google Launcher2 as the default Launcher,
Its package name is com. android. launcher.
Launcher activity name is com. android. launcher2.Launcher
Edit the packages/apps/Provision/src/com/android/DefaultActivity. java File
......
// Remove this activity from the package manager.
PackageManager pm = getPackageManager ();
// Add start
String examplePackageName = "com. android. launcher"; // modify it to be set.
Package name
String exampleActivityName = "com. android. launcher2.Launcher // please repair
Change the name of the launcher activity to be set.

Intent intent = new Intent (Intent. ACTION_MAIN );
Intent. addCategory (Intent. CATEGORY_HOME );

List <ResolveInfo> resolveInfoList =
Pm. queryIntentActivities (intent, 0 );
If (resolveInfoList! = Null ){
Int size = resolveInfoList. size ();
For (int j = 0; j <size ;){
Final ResolveInfo r = resolveInfoList. get (j );
If (! R. activityInfo. packageName. equals (examplePackageName )){
ResolveInfoList. remove (j)
Size-= 1;
} Else
{
J ++;
}
}
ComponentName [] set = new ComponentName [size];
ComponentName defaultLauncher = new
ComponentName (examplePackageName, exampleActivityName );
Int defaultMatch = 0;
For (int I = 0; I <size; I ++ ){
Final ResolveInfo resolveInfo =
ResolveInfoList. get (I );
Log. d (TAG, resolveInfo. toString ());
Set [I] = new
ComponentName (resolveInfo. activityInfo. packageName, resolveInfo. activityInfo. name );
If (defalaunlauncher. getClassName (). equals (resolveInfo. activityInfo. name )){
DefaultMatch = resolveInfo. match;
}
}
Log. d (TAG, "defamatch match =" + Integer. toHexString (defaultMatch ));
IntentFilter filter = new IntentFilter ();
Filter. addAction (Intent. ACTION_MAIN );
Filter. addCategory (Intent. CATEGORY_HOME );
Filter. addCategory (Intent. CATEGORY_DEFAULT );

Pm. clearPackagePreferredActivities (defaultLaunchr. getPackageName ());
Pm. addPreferredActivity (filter, defaultMatch, set, defalaunlauncher );
}
// Add end
// Remove this activity from the package manager.
ComponentName name = new ComponentName (this,
DefaultActivity. class );
Pm. setComponentEnabledSetting (name,
PackageManager. COMPONENT_ENABLED_STATE_DISABLED,
PackageManager. DONT_KILL_APP );
......
Modify the packages/apps/Provision/AndroidManifest. xml file and add the following statement:
<Uses-permission
Android: name = "android. permission. SET_PREFERRED_APPLICATIONS"/>
Note:
All the code added above must be placed in the pm. setComponentEnabledSetting statements.
Before,
Note:
If the above steps can be achieved, ignore the following description
If the above steps cannot be achieved
Modify packageManagerService. java
(Framework/base/services/java/com/android/server/pm /)
FindPreferredActivity method
Add the following statement to the code next to the comparison of this method
If (! Pa. mPref. sameSet (query, priority )){
If (! (Intent. getAction ()! = Null
& Intent. getAction (). equals (intent. ACTION_MAIN)
& Intent. getCategories ()! = Null
& Intent. getCategories (). contains (intent. CATEGORY_HOME) // Add
{// Add this line
Slog. I (TAG, "Result set changed, dropping preferred activity
+ Intent + "type" + resolvedType );
MSettings. mPreferredActivities. removeFilter (pa );
Return null;
} // Add this line
Slog. I (TAG, "Result set not change, not drop preferred activity
Special intent: "+ intent); // Add this line
}
You can.

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.