When there are multiple launcher on the Android system, set the boot automatically into the default launcher

Source: Internet
Author: User

After the boot is complete and unlocked, if there is more than one launcher on the Android system, a selection box pops up to let the user choose to enter a launcher. If the user does not want to choose, but want to go directly to a default launcher, how to modify?
Note: This modification is not valid for Google Now Launcher (googlehome.apk) because this app launches activity in <intent-filter> without <category android:name= "Android.intent.category.HOME"/> This option.

The following is an example of setting up Google Launcher2 as the default boot launcher
Its package name is Com.android.launcher
Launcher activity name is Com.android.launcher2.Launcher


1. Add the following code to the end of the Systemready function in Packagemanagerservice.java.
if (Isfirstboot ())
{
ADD BEGIN
String examplepackagename = "Com.android.launcher"; Please modify the package name to be set
String exampleactivityname = "Com.android.launcher2.Launcher"; Please modify the launcher activity name to be set.
Intent intent=new Intent (Intent.action_main);
Intent.addcategory (Intent.category_home);
Final int callinguserid = Userhandle.getcallinguserid ();

list<resolveinfo> resolveinfolist = queryintentactivities (Intent,null, Packagemanager.get_meta_data, Callinguserid);
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 (Defaultlauncher.getclassname (). Equals (ResolveInfo.activityInfo.name)) {
Defaultmatch = Resolveinfo.match;
}
}
SLOG.E (TAG, "defaultmatch=" +integer.tohexstring (Defaultmatch));
Intentfilter filter=new Intentfilter ();
Filter.addaction (Intent.action_main);
Filter.addcategory (Intent.category_home);
Filter.addcategory (Intent.category_default);

AddPreferredActivity2 (filter, Defaultmatch, set, Defaultlauncher);
}
ADD END
}
2. Add the AddPreferredActivity2 function to the Packagemanagerservice.java.
public void AddPreferredActivity2 (intentfilter filter, int match,
Componentname[] Set, componentname activity) {
LOG.D ("Debug_default", "AddPreferredActivity2 is called.");
Writer
Synchronized (mpackages) {
SLOG.I (TAG, "Adding preferred activity" + activity + ":");
Filter.dump (New Logprinter (Log.info, TAG), "");
MSETTINGS.EDITPREFERREDACTIVITIESLPW (0). addfilter (
New Preferredactivity (filter, match, set, activity, true));
Schedulewritesettingslocked ();
}
}
3. Modify the Packagemanagerservice.java function findpreferredactivity

(1) The original removematches to increase the judging conditions, in launcher not remove
if (! ( Intent.getaction ()! = null && intent.getaction (). Equals (intent. Action_main) && intent.getcategories ()!=null && intent.getcategories (). Contains (intent. Category_home))) {//add
SLOG.D (TAG, "launcher");
}else {
if (removematches) {
Pir.removefilter (PA);
if (debug_preferred) {
SLOG.V (TAG, "removing match" + pa.mPref.mComponent);
}
Break
}
}
(2)
if (Always &&!pa.mpref.sameset (query, priority)) {
SLOG.I (TAG, "Result set changed, dropping preferred activity for"
+ Intent + "type" + Resolvedtype);
if (debug_preferred) {
SLOG.V (TAG, "removing preferred activity since set changed"
+ pa.mPref.mComponent);
}
Pir.removefilter (PA);
Re-add the filter as a "last Chosen" entry (!always)
Preferredactivity Lastchosen = new Preferredactivity (
PA, Pa.mPref.mMatch, NULL, pa.mPref.mComponent, FALSE);
Pir.addfilter (Lastchosen);
MSETTINGS.WRITEPACKAGERESTRICTIONSLPR (USERID);
return null;
}
The above paragraph is modified to read:
if (Always &&!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
SLOG.I (TAG, "Result set changed, dropping preferred activity for"
+ Intent + "type" + Resolvedtype);
if (debug_preferred) {
SLOG.V (TAG, "removing preferred activity since set changed"
+ pa.mPref.mComponent);
}
Pir.removefilter (PA);

Re-add the filter as a "last Chosen" entry (!always)
Preferredactivity Lastchosen = new Preferredactivity (
PA, Pa.mPref.mMatch, NULL, pa.mPref.mComponent, FALSE);
Pir.addfilter (Lastchosen);
MSETTINGS.WRITEPACKAGERESTRICTIONSLPR (USERID);
return null;
}
}
SLOG.I (TAG, "Result set not change, not drop preferred activity for special intent:" +intent);//add
yay! Either the set matched or we ' re looking for the last chosen




JB Series Findpreferredactivity slightly adjusted, see below:
Modify the Findpreferredactivity method of Packagemanagerservice.java (framework/base/services/java/com/android/server/pm/), Compare this method to the following piece of code:
if (!pa.mpref.sameset (query, priority)) {
SLOG.I (TAG, "Result set changed, dropping preferred activity for" + intent + "type" + Resolvedtype);
Pir.removefilter (PA);
return null;
}

Modified to:
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
SLOG.I (TAG, "Result set changed, dropping preferred activity for" + intent + "type" + Resolvedtype);
Pir.removefilter (PA);
return null;
}//add
SLOG.I (TAG, "Result set not change, not drop preferred activity for special intent:" +intent);//add
}

If the user is in the list of all applications, manage applications, applications, and so on, find the default launcher set earlier and cancel the default values, the system will re-eject the launcher selection box.

When there are multiple launcher on the Android system, set the boot automatically into the default launcher

Related Article

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.