Android MTK 设置默认启动 Launcher


当系统存在 两个或者以上多个启动桌面Launcher的时候,往往会开机弹出一个 dialog的列表让你去选择启动那个Launcher,这个时候我们要设置开机默认

之前试过网上很多方法,没怎么起到作用,该方法测试通过,应用与Android 4.4.4 MTK 6572

\frameworks\base\services\java\com\android\server\am\ActivityManagerService.java


修改ActivityManagerService.java的startHomeActivityLocked方法
boolean startHomeActivityLocked(int userId, String reason) {
if (mFactoryTest == FactoryTest.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;
}
/**
* mtk add
* set default launcher
*/
ComponentName DefaultLauncher=new
ComponentName("com.android.launcher3","com.android.launcher3.Launcher"); //此处设置默认Launcher的包
类名
//Slog.d(TAG,"set default launcher");
final PackageManager mPm = mContext.getPackageManager();
ArrayList homeActivities = new ArrayList();
ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
ComponentName[]mHomeComponentSet = new ComponentName[homeActivities.size()];
for (int i = 0; i < homeActivities.size(); i++) {
final ResolveInfo candidate = homeActivities.get(i);
//Slog.d(TAG,"homeActivities"+candidate);
final ActivityInfo info = candidate.activityInfo;
ComponentName activityName = new ComponentName(info.packageName, info.name);
mHomeComponentSet[i] = activityName;
}
IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
mHomeFilter.addCategory(Intent.CATEGORY_HOME);
mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
ListActivities=new ArrayList();
mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,mHomeComponentSet, DefaultLauncher);
/**
* set default launcher end
*/
Intent intent = getHomeIntent();
ActivityInfo aInfo =
resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
...... PS:


二、如果预置了GMS,上面和下面合并,还需要按照下面的方法修改:

请找到PackageManagerService.java的systemReady方法,在这个方法的最后增加以下示例代码:
 if(isFirstBoot()) {
    String examplePackageName = "com.android.launcher";  //请修改为需要设置的 package name
    String exampleActivityName = "com.android.launcher2.Launcher"; //请修改为需要设置的 launcher activity name  
    Intent intent=new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    final int callingUserId = UserHandle.getCallingUserId();
    
    List resolveInfoList = queryIntentActivities(intent,null, PackageManager.GET_META_DATA,callingUserId);
    if(resolveInfoList != null){
      int size = resolveInfoList.size();
      for(int j=0;j



1.如果用户在设置->应用程序->管理应用程序->所有应用程序列表,找到之前设置的
默认Launcher,并取消了默认值,系统会重新弹出launcher选择框。但重启后会进入
上述代码设置的默认Launcher
2.
如果用户在设置->主屏幕中修改了默认的Launcher,下次重启后将进入修改后的Launcher




你可能感兴趣的:(Android,MTK开发笔记集)