Android MTK 设置默认启动 Launcher,字节跳动学习笔记

  • Post author:
  • Post category:其他


/**

  • 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,上面



版权声明:本文为m0_65145113原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。