When the system has more than one launcher, if the default launcher is not set, the boot will pop up a prompt box, listing all launcher, the user selected and set the default launcher, press the home key and later restart will go to the default launcher.
Now, I want the system to go directly to the launcher I set up instead of the popup box and select and set
Most of the online practice is to modify
Packages/apps/provision/src/com/android/defaultactivity.java
And
Framework/base/java/com/android/server/pm/packagemanagerservice.java
Two files, give a relatively good-looking link http://blog.csdn.net/z_guijin/article/details/8964890
I follow this do not achieve the desired effect, modify multiple search keywords, get another article, roughly looked at, the feeling will not be effective, but has been desperate to try to solve the problem http://blog.csdn.net/jia4525036/article/details/18036765
This article has the reference, the direct use will find some fields are not in the context, so write down this document.
Modify a file
Frameworks\base\services\java\com\android\server\am\activitymanagerservice.java
Add a method:
private void setdefaultlauncher () { String packageName = " Com.android.test "; //default Launcher package name string className = "com.android.test.MainActivity"; //Default Launcher entry &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SLOG.I (tag, "defautl packagename = " + packagename + ", default classname = " + classname); ipackagemanager pm = activitythread.getpackagemanager (); //clear the current default launcher   Arraylist<intentfilter> intentlist = new arraylist<intentfilter> (); ArrayList<ComponentName> cnList = New arraylist<componentname> (); Mcontext.getpackagemanager (). Getpreferredactivities (Intentlist, cnlist, null); IntentFilter dhIF = null; for (int i = 0; i < cnlist.size (); i++) { dhif = intentlist.get (i); if (Dhif.hasaction (intent.action_main) && Dhif.hascategory (Intent.category_home)) { mcontext.getpackagemanager (). Clearpackagepreferredactivities (Cnlist.get (i). Getpackagename ()); } } //Get all launcher activity intent intent = new intent (Intent.action_main); intent.addcategory (intent.category_home); list<resolveinfo> list = new arraylist<resolveinfo > (); try { list = pm.queryintentactivities (intent, intent.resolvetypeifneeded ( Mcontext.getcontentresolver ()), packagemanager.match_default_only); }catch (remoteexception e) { throw new runtimeexception ("Package manager has died ", e); } // get all components and the best match intentfilter filter = new intentfilter (); filter.addaction (Intent.action_main); filter.addcategory(intent.category_home); filter.addcategory ( Intent.category_default); final int n = list.size (); &NBSP;&NBSP;&NBSP;&NBSP;SLOG.D (tag, "n:::::hyhyhyhy:::: = " + n); //Setting the default launcher Componentname launcher = new componentname (Packagename, classname); componentname[] set = new ComponentName[N]; int defaultMatch = 0; for (int i = 0; i < n; i++) { Resolveinfo r = list.get (i); set[i] = new componentname (r.activityinfo.packagename, R.activityinfo.name); SLOG.D (tag, "r.activityinfo.packagename:::::hyhyhyhy:::: = " + R.activityinfo.packagename); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SLOG.D (TAG , "r.activityinfo.name:::::hyhyhyhy:::: = " + r.activityinfo.name); if (Launcher.getclassname (). Equals (R.activityInfo.name)) { defaultmatch = r.match; } } //will set the default launcher, add to System Preferences try { pm.addpreferredactivity ( Filter, defaultmatch, set, launcher); } catch (remoteexception e) { throw new runtimeexception ("Factorytest. Mainactivity : package manager has died ", e); } }
And then in the Activitymanagerservice class,
Boolean starthomeactivitylocked ()
The first line of the method invokes the added
Setdefaultlauncher ()
boolean starthomeactivitylocked () { if (mfactorytest == systemserver.factory_test_low_level && mtopaction == null) { // We are running in factory test mode, but unable to find // the factory test app, so just sit around displaying the // error message and don ' t try to start anything. return false; }////////////Setdefaultlauncher ();/////////////////////////////////////////// intent intent = new intent ( mTopAction, mtopdata != null ? uri.parse (mtopdata) : null); intent.setcomponent (mtopcomponent); if (Mfactorytest != systemserver.factory_test_low_level) { intent.addcategory (Intent.CATEGORY_HOME); } ActivityInfo Ainfo = intent.resolveactivityinfo (Mcontext.getpackagemanager (), stock_pm_flags); if (aInfo != null) { intent.setcomponent (new ComponentName ( ainfo.applicationinfo.packagename, ainfo.name)); // don ' T do this if the home app is currently being // instrumented. ProcessRecord App = getprocessrecordlocked (ainfo.processname, &nbSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;AINFO.APPLICATIONINFO.UID); if (app == null | | app.instrumentationclass == null) { intent.setflags (Intent.getflags () | intent.flag_activity_ New_task); Mmainstack.startactivitylocked (null, intent, null, null, 0, ainfo, null, null, 0, 0, 0, false, false, null); } } return true; }
After adding the method all content as above, recompile Android, burn, boot will be able to automatically enter the custom launcher
The default setting of the launcher can be canceled by the system settings, and pressing the home button will pop up launcher the Select Prompt box.
Frameworks\base\core\java\com\android\internal\app\resolveractivity.java
The Resolveractivity class is the pop-up box that chooses the open mode
Android Settings Default launcher