美文网首页
MTK P默认设置第三方应用为主桌面

MTK P默认设置第三方应用为主桌面

作者: l900 | 来源:发表于2021-08-19 12:07 被阅读0次

    概述

    大部分的系统定制都会有设置客户launcher为系统桌面的需求,在此做个修改记录

    添加客户APP

    1.创建.\vendor\mediatek\proprietary\packages\apps\custom_Launcher目录
    2.把custom_Launcher.apk放入custom_Launcher目录
    3.新建Android.mk 名称必须保持一致

     LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    # Module name should match apk name to be installed
    LOCAL_MODULE := custom_Launcher
    LOCAL_MODULE_TAGS := optional
    LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
    LOCAL_MODULE_CLASS := APPS
    LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
    LOCAL_CERTIFICATE := PRESIGNED
    LOCAL_PRIVILEGED_MODULE := true
    include $(BUILD_PREBUILT)
    

    4.\device\mediatek\common\device.mk 末尾添加
    PRODUCT_PACKAGES += custom_Launcher

    默认launcher设置

    1.获取apk的包名类名
    packageName :com.xxx.package
    className :com.xxx.package.LauncherName
    2.frameworks\base\services\core\java\com\android\server\am\ActivityManagerService.java
    startHomeActivityLocked中添加如下:

    final PackageManager mPm = mContext.getPackageManager();
    
            Intent homeIntent=new Intent();
    
            homeIntent.addCategory(Intent.CATEGORY_HOME);
    
            homeIntent.setAction(Intent.ACTION_MAIN);
            homeIntent.addCategory(Intent.CATEGORY_DEFAULT);
            ResolveInfo info = mPm.resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);
            if("android".equals(info.activityInfo.packageName)){
    
                ComponentName DefaultLauncher=new ComponentName( packageName, className ); // need modify
                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);
                    Log.d(TAG,"homeActivitie: candidate = "+candidate);
                    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);
            }
    

    移除了launcher3的修改需要添加以下:更改recent的包名类名

    \frameworks\base\core\res\res\values\config.xml

    <!--<string name="config_recentsComponentName" translatable="false">com.android.systemui/.recents.RecentsActivity</string> -->
        <string name="config_recentsComponentName" translatable="false">com.android.launcher3/com.android.quickstep.RecentsActivity</string>
    

    2021年8月19日早上12点
    谢谢!

    相关文章

      网友评论

          本文标题:MTK P默认设置第三方应用为主桌面

          本文链接:https://www.haomeiwen.com/subject/nrwobltx.html