当前位置:   article > 正文

android 13 设置默认launcher_android13 settings 添加luncher配置

android13 settings 添加luncher配置
  1. .../internal/app/ResolverActivity.java | 57 +++++++++++++++++++
  2. 1 file changed, 57 insertions(+)
  3. diff --git a/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java b/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
  4. index 6c11f41a139..e58cedb59b3 100644
  5. --- a/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
  6. +++ b/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
  7. @@ -90,6 +90,18 @@ import android.widget.TabWidget;
  8. import android.widget.TextView;
  9. import android.widget.Toast;
  10. +import android.content.ComponentName;
  11. +import android.content.Context;
  12. +import android.content.Intent;
  13. +import android.content.IntentFilter;
  14. +import android.content.pm.ActivityInfo;
  15. +import android.content.pm.PackageManager;
  16. +import android.content.pm.ResolveInfo;
  17. +import android.os.Bundle;
  18. +import android.provider.Settings;
  19. +import android.text.TextUtils;
  20. +import android.util.Log;
  21. +
  22. import com.android.internal.R;
  23. import com.android.internal.annotations.VisibleForTesting;
  24. import com.android.internal.app.AbstractMultiProfilePagerAdapter.Profile;
  25. @@ -368,12 +380,57 @@ public class ResolverActivity extends Activity implements
  26. supportsAlwaysUseOption);
  27. }
  28. +
  29. + //set default launcher
  30. + private void setDefaultLauncher(){
  31. + Log.d("dbg","setDefaultLauncher");
  32. + final PackageManager mPm = getPackageManager();
  33. + Intent homeIntent = new Intent();
  34. + homeIntent.addCategory(Intent.CATEGORY_HOME);
  35. + homeIntent.setAction(Intent.ACTION_MAIN);
  36. + homeIntent.addCategory(Intent.CATEGORY_DEFAULT);
  37. +
  38. + //get CurrentLauncher
  39. + ResolveInfo info = mPm.resolveActivity(homeIntent, 0);
  40. + String currentPkg = "android";
  41. + if (info != null && !TextUtils.isEmpty(info.activityInfo.packageName)
  42. + && !TextUtils.equals(info.activityInfo.packageName, "android")) {
  43. + currentPkg = info.activityInfo.packageName;
  44. + }
  45. + if (TextUtils.equals(info.activityInfo.packageName, "android")) { //if there is a default Launcher?
  46. + String defaultlauncherpckname="your_launcher_package_name";
  47. + String defaultlauncherclsname="your_launcher_activity_class_name";
  48. + ComponentName DefaultLauncher = new ComponentName(defaultlauncherpckname, defaultlauncherclsname);
  49. + ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
  50. + ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
  51. + ComponentName[] mHomeComponentSet = new ComponentName[homeActivities.size()];
  52. + for (int i = 0; i < homeActivities.size(); i++) {
  53. + final ResolveInfo candidate = homeActivities.get(i);
  54. + final ActivityInfo activityInfo = candidate.activityInfo;
  55. + ComponentName activityName = new ComponentName(activityInfo.packageName, activityInfo.name);
  56. + mHomeComponentSet[i] = activityName;
  57. + }
  58. + IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
  59. + mHomeFilter.addCategory(Intent.CATEGORY_HOME);
  60. + mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
  61. + List<ComponentName> Activities = new ArrayList();
  62. + mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY, mHomeComponentSet, DefaultLauncher);
  63. + }
  64. + }
  65. +
  66. +
  67. protected void onCreate(Bundle savedInstanceState, Intent intent,
  68. CharSequence title, int defaultTitleRes, Intent[] initialIntents,
  69. List<ResolveInfo> rList, boolean supportsAlwaysUseOption) {
  70. setTheme(appliedThemeResId());
  71. super.onCreate(savedInstanceState);
  72. + if(mResolvingHome){
  73. + setDefaultLauncher();
  74. + finish();
  75. + return;
  76. + }
  77. // Determine whether we should show that intent is forwarded
  78. // from managed profile to owner or other way around.
  79. setProfileSwitchMessage(intent.getContentUserHint());

打入上面的patch,修改包名类名成你的launcher的包名,类名打包即可。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/787713
推荐阅读
相关标签
  

闽ICP备14008679号