.../internal/app/ResolverActivity.java | 57 +++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java b/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
index 6c11f41a139..e58cedb59b3 100644
--- a/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
+++ b/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
@@ -90,6 +90,18 @@ import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.util.Log;
+
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.AbstractMultiProfilePagerAdapter.Profile;
@@ -368,12 +380,57 @@ public class ResolverActivity extends Activity implements
supportsAlwaysUseOption);
}
+
+ //set default launcher
+ private void setDefaultLauncher(){
+ Log.d("dbg","setDefaultLauncher");
+ final PackageManager mPm = getPackageManager();
+ Intent homeIntent = new Intent();
+ homeIntent.addCategory(Intent.CATEGORY_HOME);
+ homeIntent.setAction(Intent.ACTION_MAIN);
+ homeIntent.addCategory(Intent.CATEGORY_DEFAULT);
+
+ //get CurrentLauncher
+ ResolveInfo info = mPm.resolveActivity(homeIntent, 0);
+ String currentPkg = "android";
+ if (info != null && !TextUtils.isEmpty(info.activityInfo.packageName)
+ && !TextUtils.equals(info.activityInfo.packageName, "android")) {
+ currentPkg = info.activityInfo.packageName;
+ }
+ if (TextUtils.equals(info.activityInfo.packageName, "android")) { //if there is a default Launcher?
+ String defaultlauncherpckname="your_launcher_package_name";
+ String defaultlauncherclsname="your_launcher_activity_class_name";
+ ComponentName DefaultLauncher = new ComponentName(defaultlauncherpckname, defaultlauncherclsname);
+ ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
+ 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);
+ final ActivityInfo activityInfo = candidate.activityInfo;
+ ComponentName activityName = new ComponentName(activityInfo.packageName, activityInfo.name);
+ mHomeComponentSet[i] = activityName;
+ }
+ IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
+ mHomeFilter.addCategory(Intent.CATEGORY_HOME);
+ mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
+ List<ComponentName> Activities = new ArrayList();
+ mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY, mHomeComponentSet, DefaultLauncher);
+ }
+ }
+
+
protected void onCreate(Bundle savedInstanceState, Intent intent,
CharSequence title, int defaultTitleRes, Intent[] initialIntents,
List<ResolveInfo> rList, boolean supportsAlwaysUseOption) {
setTheme(appliedThemeResId());
super.onCreate(savedInstanceState);
+ if(mResolvingHome){
+ setDefaultLauncher();
+ finish();
+ return;
+ }
// Determine whether we should show that intent is forwarded
// from managed profile to owner or other way around.
setProfileSwitchMessage(intent.getContentUserHint());
打入上面的patch,修改包名类名成你的launcher的包名,类名打包即可。