@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void tryNewMiuiBadge(Context context, int badgeCount) throws ShortcutBadgeException { if (resolveInfo == null) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); } if (resolveInfo != null) { NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(context) .setContentTitle("") .setContentText("") .setSmallIcon(resolveInfo.getIconResource()); Notification notification = builder.build(); try { Field field = notification.getClass().getDeclaredField("extraNotification"); Object extraNotification = field.get(notification); Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); method.invoke(extraNotification, badgeCount); mNotificationManager.notify(0, notification); } catch (Exception e) { throw new ShortcutBadgeException("not able to set badge", e); } } }
Drawable loadIconForResolveInfo(ResolveInfo ri) { Drawable dr; try { if (ri.resolvePackageName != null && ri.icon != 0) { dr = getIcon(mPm.getResourcesForApplication(ri.resolvePackageName), ri.icon); if (dr != null) { return dr; } } final int iconRes = ri.getIconResource(); if (iconRes != 0) { dr = getIcon(mPm.getResourcesForApplication(ri.activityInfo.packageName), iconRes); if (dr != null) { return dr; } } } catch (PackageManager.NameNotFoundException e) { VLog.e(TAG, "Couldn't find resources for package\n" + VLog.getStackTraceString(e)); } return ri.loadIcon(mPm); }
intent.setType("image/jpeg"); intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.getIconResource()));
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void tryNewMiuiBadge(Context context, int badgeCount) throws ShortcutBadgeException { if (resolveInfo == null) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); } if (resolveInfo != null) { NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(context) .setContentTitle("") .setContentText("") .setSmallIcon(resolveInfo.getIconResource()); Notification notification = builder.build(); try { Field field = notification.getClass().getDeclaredField("extraNotification"); Object extraNotification = field.get(notification); Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); method.invoke(extraNotification, badgeCount); mNotificationManager.notify(0, notification); } catch (Exception e) { throw new ShortcutBadgeException("not able to set badge", e); } } }
private Drawable loadIconForResolveInfo(ResolveInfo info) { try { final int iconRes = info.getIconResource(); if (iconRes != 0) { Resources res = mManager.getResourcesForApplication(info.activityInfo.packageName); Drawable icon = ApiCompatibilityUtils.getDrawable(res, iconRes); return icon; } } catch (NameNotFoundException | NotFoundException e) { // Could not find the icon. loadIcon call below will return the default app icon. } return info.loadIcon(mManager); }
public Drawable getIcon(int density) { int iconRes = mResolveInfo.getIconResource(); Resources resources = null; Drawable icon = null; // Get the preferred density icon from the app's resources if (density != 0 && iconRes != 0) { try { resources = mPm.getResourcesForApplication(mActivityInfo.applicationInfo); icon = resources.getDrawableForDensity(iconRes, density); } catch (NameNotFoundException | Resources.NotFoundException exc) { } } // Get the default density icon if (icon == null) { icon = mResolveInfo.loadIcon(mPm); } if (icon == null) { resources = Resources.getSystem(); icon = resources.getDrawableForDensity(android.R.mipmap.sym_def_app_icon, density); } return icon; }
public Drawable getIcon(int density) { int iconRes = mResolveInfo.getIconResource(); Resources resources = null; Drawable icon = null; // Get the preferred density icon from the app's resources if (density != 0 && iconRes != 0) { try { resources = mPm.getResourcesForApplication(mActivityInfo.applicationInfo); icon = resources.getDrawableForDensity(iconRes, density); } catch (NameNotFoundException | Resources.NotFoundException exc) { } } // Get the default density icon if (icon == null) { icon = mResolveInfo.loadIcon(mPm); } if (icon == null) { resources = Resources.getSystem(); icon = resources.getDrawableForDensity(android.R.mipmap.sym_def_app_icon, density); } return icon; }
Drawable loadIconForResolveInfo(ResolveInfo ri) { Drawable dr; try { if (ri.resolvePackageName != null && ri.icon != 0) { dr = getIcon(mPm.getResourcesForApplication(ri.resolvePackageName), ri.icon); if (dr != null) { return dr; } } final int iconRes = ri.getIconResource(); if (iconRes != 0) { dr = getIcon(mPm.getResourcesForApplication(ri.activityInfo.packageName), iconRes); if (dr != null) { return dr; } } } catch (PackageManager.NameNotFoundException e) { VLog.e(TAG, "Couldn't find resources for package\n" + VLog.getStackTraceString(e)); } return ri.loadIcon(mPm); }
public Drawable getIcon(int density, IconPackHelper helper) { if (helper != null && helper.isIconPackLoaded()) { int iconId = helper.getResourceIdForActivityIcon(mActivityInfo); if (iconId != 0) { isThemed = true; return helper.getIconPackResources().getDrawableForDensity(iconId, density); } } int iconRes = mResolveInfo.getIconResource(); Resources resources = null; Drawable icon = null; // Get the preferred density icon from the app's resources if (density != 0 && iconRes != 0) { try { resources = mPm.getResourcesForApplication(mActivityInfo.applicationInfo); icon = resources.getDrawableForDensity(iconRes, density); } catch (NameNotFoundException | Resources.NotFoundException exc) { } } // Get the default density icon if (icon == null) { icon = mResolveInfo.loadIcon(mPm); } if (icon == null) { resources = Resources.getSystem(); icon = resources.getDrawableForDensity(android.R.mipmap.sym_def_app_icon, density); } return icon; }
Drawable loadIconForResolveInfo(ResolveInfo ri) { Drawable dr; try { if (ri.resolvePackageName != null && ri.icon != 0) { dr = getIcon(mPm.getResourcesForApplication(ri.resolvePackageName), ri.icon); if (dr != null) { return dr; } } final int iconRes = ri.getIconResource(); if (iconRes != 0) { dr = getIcon(mPm.getResourcesForApplication(ri.activityInfo.packageName), iconRes); if (dr != null) { return dr; } } } catch (PackageManager.NameNotFoundException e) { VLog.e(TAG, "Couldn't find resources for package\n" + VLog.getStackTraceString(e)); } return ri.loadIcon(mPm); }