如何删除应用程序快捷方式图标上的徽章?

8

enter image description here如何在Android应用程序快捷图标中删除徽章?当我以编程方式创建应用程序快捷方式时,除了指定的快捷方式图标外,应用程序图标还会出现在图标的右下角。我不想要那个徽章。

这是我使用的代码

    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
    }
}

我没有使用推送通知。我试图为我的应用程序添加一个快捷方式,但问题只出现在Oreo版本中。 - Athira
1
请放置一些关于您的问题的图片。 - Abner Escócio
你能分享导致这个结果的代码吗? - madlymad
@MartinZeitler 我已经添加了代码。我的问题与您建议的内容没有相似之处。请至少阅读一遍我的问题。 - Athira
@Athira 你找到解决方案了吗?我已经花了很多时间进行研究,但是找不到答案。有些应用程序仍然可以做到这一点,但我做不到@@ - Robotic Vn
显示剩余9条评论
7个回答

2
不,没有办法。这些附加选项是由启动器添加的,而不是您的应用程序本身。显然,如果您的应用程序不能卸载(例如它是系统应用程序),则卸载选项将不存在。

0

ShortcutInfoShortcutManager都没有这样的选项。它取决于启动器,应该显示此标记,以便用户知道将在哪个应用程序中打开。如果没有这个图标,就无法识别添加它的应用程序(除了打开),这对用户不太友好...例如,您可以通过添加例如 FB 图标和“Facebook”快捷方式名称来模拟另一个应用程序,并且通过该快捷方式打开的Activity可能是虚假登录屏幕。简而言之:出于安全原因,应该存在/应该存在这个图标。

在我的启动器上,长按立即开始移动快捷方式(没有下拉菜单作为启动器图标),而我在屏幕顶部没有“应用程序信息”选项(在“移动模式”下),只有“删除”。

也许考虑添加一个AppWidget,它被设计成启动器图标和应用程序名称?自API25以来,快捷方式已经可用,小部件从一开始就存在,自API26以来,您可以requestPinAppWidget(类似于添加快捷方式的对话框样式)。

0

通过小部件屏幕(类似于this video)添加快捷方式(而不是应用程序小部件)可能是一种解决方法。创建一个过滤器活动<action android:name="android.intent.action.CREATE_SHORTCUT" />,并通过手动创建Intent.EXTRA_SHORTCUT_INTENT意图(而不是通过shortcutManager.createShortcutResultIntent())在该活动中创建快捷方式,并使用setResult()返回它。

有关详细信息,请参见this answer。请注意,在使用不同的启动器时,实际行为仍可能不同(在某些启动器下可能无法工作)。我只在Android 11和Android 12下测试了Pixel Launcher和Microsoft Launcher。


-1

首先从PlayStore下载一个图标包(有很多选择)。 返回到含有需要更改的图标的屏幕。 按住您想要更改的图标(即带有额外Chrome标志的图标),然后按编辑。 按更改图标。 它会给您选择从图标包中选择的选项,因此请按那个选项。 然后您将有大量的图标可供选择,因此请选择最能代表当前图标或选择完全不同的东西。 然后点击确定。 它将更改图标并且没有额外的标记。


1
显然,OP是在询问如何从他的应用程序内部进行更改,而不是作为用户... - gxcare

-2

你可以尝试这个,也许对你有用。 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);

另一种解决方案请访问此链接:https://stackoverflow.com/questions/51061462/disabling-oreo-notification-dot - Vasudev Vyas
1
这是通知徽章,你看不到我问题中的图片吗? - Athira
你的问题是“如何移除应用程序快捷图标上的徽章?”我能看到这个问题。然而,你没有在这里放置你的代码,我们怎么能给出正确的答案呢?不要聪明过头了。 - Vasudev Vyas
请阅读问题描述 - Athira
2
虽然这段代码可能解决了OP的问题,但最好还是解释一下你的代码如何解决OP的问题。这样,未来的访问者可以从您的帖子中学习,并将其应用到自己的代码中。SO不是编码服务,而是知识资源。此外,高质量、完整的答案更有可能被点赞。这些特点以及所有帖子都必须是自包含的要求,是SO作为一个平台的一些优势,使其与论坛区分开来。您可以编辑以添加其他信息和/或使用源文档补充您的解释。 - ysf

-2
在你的Manifest.xml文件中添加以下行:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

创建桌面快捷方式的代码:
 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);


    }

这不起作用,自 OREO 以来 INSTALL_SHORTCUT 不再工作。https://developer.android.com/about/versions/oreo/android-8.0-changes#as - dcanh121

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

如何删除低于Oreo版本的徽章? - Silambarasan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接