@Test public void testAddToIntent_badgeApplication() { ApplicationInfo appInfo = spy(mContext.getApplicationInfo()); doReturn(ContextCompat.getDrawable(mContext, R.drawable.test_drawable_green)) .when(appInfo).loadIcon(any(PackageManager.class)); doReturn(appInfo).when(mContext).getApplicationInfo(); Intent intent = new Intent(); mBuilder.setAlwaysBadged() .build() .addToIntent(intent); assertEquals(mAction, intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT)); assertNull(intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE)); verifyBadgeBitmap(intent, ContextCompat.getColor(mContext, R.color.test_red), ContextCompat.getColor(mContext, R.color.test_green)); }
Intent addToIntent(Intent outIntent) { outIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mIntents[mIntents.length - 1]) .putExtra(Intent.EXTRA_SHORTCUT_NAME, mLabel.toString()); if (mIcon != null) { Drawable badge = null; if (mIsAlwaysBadged) { PackageManager pm = mContext.getPackageManager(); if (mActivity != null) { try { badge = pm.getActivityIcon(mActivity); } catch (PackageManager.NameNotFoundException e) { } } if (badge == null) { badge = mContext.getApplicationInfo().loadIcon(pm); } } mIcon.addToShortcutIntent(outIntent, badge, mContext); } return outIntent; }
ShortcutInfoCompat { Intent addToIntent(Intent outIntent) { outIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mIntents[mIntents.length - 1]) .putExtra(Intent.EXTRA_SHORTCUT_NAME, mLabel.toString()); if (mIcon != null) { Drawable badge = null; if (mIsAlwaysBadged) { PackageManager pm = mContext.getPackageManager(); if (mActivity != null) { try { badge = pm.getActivityIcon(mActivity); } catch (PackageManager.NameNotFoundException e) { } } if (badge == null) { badge = mContext.getApplicationInfo().loadIcon(pm); } } mIcon.addToShortcutIntent(outIntent, badge, mContext); } return outIntent; } }
ShortcutInfoCompat { Intent addToIntent(Intent outIntent) { outIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mIntents[mIntents.length - 1]) .putExtra(Intent.EXTRA_SHORTCUT_NAME, mLabel.toString()); if (mIcon != null) { Drawable badge = null; if (mIsAlwaysBadged) { PackageManager pm = mContext.getPackageManager(); if (mActivity != null) { try { badge = pm.getActivityIcon(mActivity); } catch (PackageManager.NameNotFoundException e) { } } if (badge == null) { badge = mContext.getApplicationInfo().loadIcon(pm); } } mIcon.addToShortcutIntent(outIntent, badge, mContext); } return outIntent; } private  ShortcutInfoCompat(); }
ShortcutInfoCompat { Intent addToIntent(Intent outIntent) { outIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mIntents[mIntents.length - 1]) .putExtra(Intent.EXTRA_SHORTCUT_NAME, mLabel.toString()); if (mIcon != null) { Drawable badge = null; if (mIsAlwaysBadged) { PackageManager pm = mContext.getPackageManager(); if (mActivity != null) { try { badge = pm.getActivityIcon(mActivity); } catch (PackageManager.NameNotFoundException e) { } } if (badge == null) { badge = mContext.getApplicationInfo().loadIcon(pm); } } mIcon.addToShortcutIntent(outIntent, badge, mContext); } return outIntent; } private  ShortcutInfoCompat(); @RequiresApi(25) ShortcutInfo toShortcutInfo(); @NonNull String getId(); @Nullable ComponentName getActivity(); @NonNull CharSequence getShortLabel(); @Nullable CharSequence getLongLabel(); @Nullable CharSequence getDisabledMessage(); @NonNull Intent getIntent(); @NonNull Intent[] getIntents(); }
ShortcutInfoCompat { Intent addToIntent(Intent outIntent) { outIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mIntents[mIntents.length - 1]) .putExtra(Intent.EXTRA_SHORTCUT_NAME, mLabel.toString()); if (mIcon != null) { Drawable badge = null; if (mIsAlwaysBadged) { PackageManager pm = mContext.getPackageManager(); if (mActivity != null) { try { badge = pm.getActivityIcon(mActivity); } catch (PackageManager.NameNotFoundException e) { } } if (badge == null) { badge = mContext.getApplicationInfo().loadIcon(pm); } } mIcon.addToShortcutIntent(outIntent, badge, mContext); } return outIntent; } private  ShortcutInfoCompat(); @RequiresApi(25) ShortcutInfo toShortcutInfo(); @NonNull String getId(); @Nullable ComponentName getActivity(); @NonNull CharSequence getShortLabel(); @Nullable CharSequence getLongLabel(); @Nullable CharSequence getDisabledMessage(); @NonNull Intent getIntent(); @NonNull Intent[] getIntents();  }