Remove badge from custom android icon

487 views Asked by At

I am creating an application for creating icons, like Ume Icon Changer and now I am using this code to create an icon

    public static void createShortCut3(Context context, Drawable drawable, String shortcutname, String packagename){
    Intent intent = context.getPackageManager().getLaunchIntentForPackage(packagename);
    BitmapDrawable bd = (BitmapDrawable) drawable;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        ShortcutManager shortcutManager =
                context.getSystemService(ShortcutManager.class);

        if (shortcutManager.isRequestPinShortcutSupported()) {
            ShortcutInfo pinShortcutInfo =
                    new ShortcutInfo.Builder(context, "app-shortcut")
                            .setIntent(intent)
                            .setShortLabel(shortcutname)
                            .setIcon(Icon.createWithAdaptiveBitmap(bd.getBitmap()))
                            .build();

            Intent pinnedShortcutCallbackIntent =
                    null;
            pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo);

            PendingIntent successCallback = PendingIntent.getBroadcast(context, 0,
                    pinnedShortcutCallbackIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            shortcutManager.requestPinShortcut(pinShortcutInfo,
                    successCallback.getIntentSender());

        }
    }
}

But all my icons are created with this badge.

enter image description here

As I understand it, you can't just remove it. But in ume icon changer and in other applications this is done somehow through the widget.

How can I implement a similar function?

1

There are 1 answers

0
Gary Wang On

Yes, you can create shortcuts without that app icon badge by creating shortcuts through the widget via the deprecated Intent.EXTRA_SHORTCUT_INTENT intent type. Create an activity that filter <action android:name="android.intent.action.CREATE_SHORTCUT" />, and create the shortcut in that activity by manually creating an Intent.EXTRA_SHORTCUT_INTENT intent (instead of via shortcutManager.createShortcutResultIntent()) and returning it with setResult().

See this answer for details. Please note that the actual behavior may still be different when using a different launcher (it may not work under some launcher). I only tested with Pixel Launcher and Microsoft Launcher under Android 11 and Android 12.