How to remove the badge in app shortcut icon?

12.7k views Asked by At

enter image description hereHow to remove the badge in app shortcut icon in android? When i create app shortcut programmatically, along with the icon specified for shortcut, app icon comes at the bottom-right corner of the icon. I don't want that badge.

Here is the code I used

    public static void addShortcutToHomeScreen(Context context)
{
    if (ShortcutManagerCompat.isRequestPinShortcutSupported(context))
    {
        ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, "#1")
                .setIntent(new Intent(context, Splash.class).setAction(Intent.ACTION_MAIN)) // !!! intent's action must be set on oreo
                .setShortLabel("Test")
                .setIcon(IconCompat.createWithResource(context, R.drawable.logo))
                .build();
        ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null);
    }
    else
    {
        // Shortcut is not supported by your launcher
    }
}
8

There are 8 answers

1
Someone On

First download an icon pack from PlayStore (loads to choose from). Go back to the screen with the offending icon. Press and hold icon you want to change (i.e. the one with the extra Chrome logo) and press edit. Press change icon. It will give you option to choose from the icon pack so press that. You will then have a large choice of icons so choose the one which best represents the current icon or choose something wildly different. Then tap OK. It will change the icon and have no extra badge.

5
Vasudev Vyas On

Try this may be work for you. mChannel.setShowBadge(false);

String id = "my_channel_01";
CharSequence name = getString(R.string.channel_name);
String description = getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.setShowBadge(false);

NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(mChannel);
1
Kintan Patel On

Add below line in your Manifest.xml

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

Code for creating a shortcut on Desktop,

 private void addShortcut() {
        //Adding shortcut for MainActivity
        //on Home screen
        Intent shortcutIntent = new Intent(getApplicationContext(), BottomNavigationActivity.class);
        shortcutIntent.setAction(Intent.ACTION_MAIN);

        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "My Shortcut");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                        R.drawable.alert_clock));
        addIntent.putExtra("duplicate", false);
        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        getApplicationContext().sendBroadcast(addIntent);


    }
0
snachmsm On

there is no such option for ShortcutInfo nor ShortcutManager. it depends on launcher and it should show this badge that user will know in which app it will open. without this icon there is no option to recognize which app added it (besides opening), thats not so user friendly... for example you could impersonate another app by adding e.g. FB icon and "Facebook" shortcut name, and Activity opened by this shortcut may be faked log-in screen. in short: this icon is/should be there for security reasons

in my launcher long press starts moving shortcut immediately (no dropdown menu as for launcher icon) and I don't have "App info" option on top of screen (in "moving mode"), only "Remove"

maybe consider adding an AppWidget stylized as launcher icon with app name? shortcuts are available since API25, widges are there from start, and since API26 you can requestPinAppWidget (similar dialog style as for adding shortcut)

1
Umesh Maurya On
private void createNotificationChannel() {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = getString(R.string.channel_name);
        String description = getString(R.string.channel_description);
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
        channel.setDescription(description);
         channel.setShowBadge(false)

        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }
}
0
Gary Wang On

Adding a shortcut (NOT app widget) via the Widgets screen (something like this video) could be a workaround. 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.

0
Vishal2 vasundhara On

No, there is no way. These additional options are added by launcher, not your app itself. Obviously, uninstall options will be not there if your app is not possible to be uninstalled (it's system app for example).

0
XaMi On

After a lot of research I found two ways we can create a shortcut programmatically of any app without badge

  1. By using Widget We can achieve this by dynamically creating widgets. If anyone wants the code for this, I can provide it as well.

  2. Create an Activity with transparent launcher icon [1]: https://i.stack.imgur.com/EZVAX.png

use this setActivity method for set our transparent launcher icon activity to shortcut

shortcutInfo.setActivity(ComponentName(mActivity!!, OpenAppActivity::class.java))

Complete method of 2nd option

fun addShortcut(bitmap: Bitmap?) {
    val launchIntent =
        mActivity!!.packageManager.getLaunchIntentForPackage(MApplication.packageNameApp.takeIf { it.isNotEmpty() }
            ?: mActivity!!.packageName)
    val shortcutInfo = ShortcutInfoCompat.Builder(
        mActivity!!.applicationContext,
        mainViewModel.selectedApp!!.appName
    )
        .setIntent(launchIntent!!)
        .setShortLabel("test")
        .setAlwaysBadged()
        .setActivity(ComponentName(mActivity!!, OpenAppActivity::class.java))
        .setIcon(IconCompat.createWithBitmap(bitmap!!)).build()
    val broadcastIntent = Intent(Intent.ACTION_CREATE_SHORTCUT)
    mActivity?.registerReceiver(
        object : BroadcastReceiver() {
            override fun onReceive(
                c: Context?, intent: Intent
            ) {
                Toast.makeText(
                    mActivity!!.applicationContext,
                    "Icon Created",
                    Toast.LENGTH_SHORT
                ).show()
                mActivity!!.unregisterReceiver(this)
            }
        }, IntentFilter(
            Intent.ACTION_CREATE_SHORTCUT
        ), Context.RECEIVER_NOT_EXPORTED
    )
    val successCallback = PendingIntent.getBroadcast(
        mActivity!!,
        99,
        broadcastIntent,
        PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
    )
    ShortcutManagerCompat.requestPinShortcut(
        requireContext(),
        shortcutInfo,
        successCallback.intentSender
    )
}