How to remove the badge in app shortcut icon?
Asked Answered
G

8

8

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
    }
}
Gilstrap answered 7/6, 2018 at 12:14 Comment(14)
what technology or platform you use for sending push notification?Nay
I am not using push notification. I was trying to add a shortcut for my app, the issue is in oreo only.Gilstrap
Put some image of your issueDenunciation
Add your shortcuts code here. so we get some idea.Explanatory
Can you share the code that ended in this result?Analogical
Please read this doc. developer.android.com/training/notify-user/badges#javaClemmy
Have u able to check this Android 8.0’s Pinned Shortcuts androidauthority.com/…Ferreira
My question is not about notification badge. It is app shortcut. @MartinZeitlerGilstrap
@MartinZeitler i have added the code. My question has no similarity to what you suggested. At least read my question once,Gilstrap
I haven't mentioned anywhere that it is a notification badge.Gilstrap
this might not even be possible... with only a screenshot, this can easily be misleading (there's lots of deleted answers taking it for a notification badge)... this shows it... it's a feature, to see what application it even isAshy
@MartinZeitler Thank you. But whatsapp and clean master apps creates shortcuts automatically. How?Gilstrap
@Gilstrap it's probably not a shortcut icon, but a common app launcher icon.Ashy
@Gilstrap Did you find the solution? I have spent many hours researching but can not find an answer. Some app still can make this but I can not @@Zwolle
P
2

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).

Parcel answered 12/10, 2018 at 8:31 Comment(0)
V
1

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.sstatic.net/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
    )
}
Volkslied answered 27/2 at 6:21 Comment(0)
A
0

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)

Aristate answered 5/4, 2019 at 8:40 Comment(0)
P
0

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.

Preindicate answered 21/2, 2022 at 13:40 Comment(0)
H
-1

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.

Hawkeyed answered 21/3, 2019 at 9:21 Comment(1)
The OP was obviously asking how to change this from within his app, not as an user...Burchett
E
-2

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);
Explanatory answered 30/3, 2019 at 9:29 Comment(5)
another solution follow this link : #51061962Explanatory
This is notification badge, can't you see the image in my question?Gilstrap
your question is "How to remove the badge in-app shortcut icon?". I can see the question. however, you are not placing your code over here how can we give the right answer. don't be over smart.Explanatory
Read question description alsoGilstrap
While this code may resolve the OP's issue, it is best to include an explanation as to how your code addresses the OP's issue. In this way, future visitors can learn from your post, and apply it to their own code. SO is not a coding service, but a resource for knowledge. Also, high quality, complete answers are more likely to be upvoted. These features, along with the requirement that all posts are self-contained, are some of the strengths of SO as a platform, that differentiates it from forums. You can edit to add additional info &/or to supplement your explanations with source documentation.Entry
G
-2

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);


    }
Gilud answered 2/4, 2019 at 9:5 Comment(1)
This does not work since OREO. INSTALL_SHORTCUT does not work. developer.android.com/about/versions/oreo/…Donner
H
-2
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);
    }
}
Hammonds answered 5/4, 2019 at 10:56 Comment(1)
how to remove badge lower than oreo?Gayla

© 2022 - 2024 — McMap. All rights reserved.