赞
踩
系统三方图标规则不统一,第三方应用的 icon 不美观,或者跟系统主题风格不一致,此时就有替换三方 Launcher 图标的需求,需要系统 Launcher 通过包名在程序中替换图标。
修改类
frameworks/libs/systemui/iconloaderlib/src/com/android/launcher3/icons/cache
方法
protected CacheEntry cacheLocked( @NonNull ComponentName componentName, @NonNull UserHandle user, @NonNull Supplier<T> infoProvider, @NonNull CachingLogic<T> cachingLogic, boolean usePackageIcon, boolean useLowResIcon) { assertWorkerThread(); ComponentKey cacheKey = new ComponentKey(componentName, user); CacheEntry entry = mCache.get(cacheKey); if (entry == null || (entry.bitmap.isLowRes() !useLowResIcon)) { entry = new CacheEntry(); if (cachingLogic.addToMemCache()) { mCache.put(cacheKey, entry); } // Check the DB first. T object = null; boolean providerFetchedOnce = false; if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) { object = infoProvider.get(); providerFetchedOnce = true; if (object != null) { entry.bitmap = cachingLogic.loadIcon(mContext, object); } else { if (usePackageIcon) { CacheEntry packageEntry = getEntryForPackageLocked( componentName.getPackageName(), user, false); if (packageEntry != null) { if (DEBUG) Log.d(TAG, "using package default icon for " + componentName.toShortString()); entry.bitmap = packageEntry.bitmap; entry.title = packageEntry.title; entry.contentDescription = packageEntry.contentDescription; } } if (entry.bitmap == null) { if (DEBUG) Log.d(TAG, "using default icon for " + componentName.toShortString()); entry.bitmap = getDefaultIcon(user); } } } f (TextUtils.isEmpty(entry.title)) { if (object == null && !providerFetchedOnce) { object = infoProvider.get(); providerFetchedOnce = true; } if (object != null) { entry.title = cachingLogic.getLabel(object); entry.contentDescription = mPackageManager.getUserBadgedLabel( cachingLogic.getDescription(object, entry.title), user); } } } // **替换修改图标 start ** if("替换应用的包名".equals(componentName.getPackageName().toString())) { entry.bitmap = BitmapInfo.of(BitmapFactory.decodeResource(mContext.getResources(), mContext.getResources().getIdentifier("替换应用的图标", "mipmap", mContext.getPackageName())), 0); } // **替换修改图标 end.** return entry; }
编译刷机,可以看到第三方应用图标已经替换成功,此方法经过验证有效,希望能帮到做系统开发的同学,大家多多交流,欢迎大家留言!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。