以设置Google Launcher2作为默认启动的Launcher为例,
其package name 为 com.android.launcher
launcher activity name 为 com.android.launcher2.Launcher
1、请在PackageManagerService.java中的systemReady函数的最后中增加以下代码。
if(isFirstBoot())
{
//MTK ADD BEGIN
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
3.修改PackageManagerService.java的函数findPreferredActivity
(1) 对原来的removeMatches 增加判断条件,在launcher时不remove
if(!(intent.getAction() != null && intent.getAction().equals(intent.ACTION_MAIN) && intent.getCategories()!=null && intent.getCategories().contains(intent.CATEGORY_HOME))) { //MTK ADD
Slog.d(TAG,"launcher");
}else{
if (removeMatches) {
pir.removeFilter(pa);
if (DEBUG_PREFERRED) {
Slog.v(TAG, "Removing match " + pa.mPref.mComponent);
}
(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;
}
上面这段修改为下面的内容:
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))) { //MTK 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);//MTK ADD
// Yay! Either the set matched or we're looking for the last chosen
特别说明:
JB系列findPreferredActivity略有调整,见下面:
修改 packageManagerService.java (framework/base/services/java/com/android/server/pm/)的findPreferredActivity方法,将此方法比较靠后的一段代码:
if (!pa.mPref.sameSet(query, priority)) {
Slog.i(TAG, "Result set changed, dropping preferred activity for " + intent + " type " + resolvedType);
pir.removeFilter(pa);
return null;
}
修改为:
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))) { //MTK ADD
Slog.i(TAG, "Result set changed, dropping preferred activity for "+ intent + " type " + resolvedType);
pir.removeFilter(pa);
return null;
} //MTK ADD
Slog.i(TAG,"Result set not change, not drop preferred activity for special intent: "+intent);//MTK ADD
}
PS:
如果用户在设置->应用程序->管理应用程序->所有应用程序列表,找到之前设置的默认Launcher,并取消了默认值,系统会重新弹出launcher选择框。
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
相关推荐: “前端”工匠系列(二):合格的工匠,怎么做好价值落地 | 京东云技术团队
一、”技术鄙视链?” 如果你是一个技术人,相信都知道技术圈有个相互的鄙视链,这个链条从技术人自己认知的角度在以业务价值为中心嵌套的一层一层的环,就像洋葱,具体的描述这里不赘述了。 出门左拐随便抓住一个人问一下。这种偏自嘲类的观点,有点类似”程序员的穿着必须是格…