【问题标题】:How to remove the badge in app shortcut icon?如何删除应用快捷方式图标中的徽章?
【发布时间】:2022-02-21 22:03:28
【问题描述】:

如何去除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 中。
  • 放一些你的问题的图片
  • 在此处添加您的快捷方式代码。所以我们有一些想法。
  • 你能分享以这个结果结尾的代码吗?

标签: android android-shortcut pinned-shortcut


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    也许考虑添加一个AppWidget 风格化为带有应用名称的启动器图标?从 API25 开始提供快捷方式,从一开始就有小部件,从 API26 开始您可以requestPinAppWidget(与添加快捷方式类似的对话框样式)

    【讨论】:

      【解决方案3】:

      添加快捷方式(不是应用小部件)通过小部件屏幕(类似于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 进行了测试。

      【讨论】:

        【解决方案4】:

        首先从 PlayStore 下载一个图标包(可供选择的负载)。 返回带有违规图标的屏幕。 按住您要更改的图标(即带有额外 Chrome 徽标的图标),然后按编辑。 按更改图标。 它会给你从图标包中选择的选项,所以按下它。 然后,您将有大量图标可供选择,因此请选择最能代表当前图标的图标,或者选择完全不同的图标。 然后点击确定。 它将改变图标并且没有额外的徽章。

        【讨论】:

        • OP 显然是在询问如何从他的应用程序中更改此设置,而不是作为用户...
        【解决方案5】:

        试试这可能对你有用。 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);
        

        【讨论】:

        • 另一个解决方案请点击此链接:stackoverflow.com/questions/51061462/…
        • 这是通知徽章,你看不到我问题中的图片吗?
        • 您的问题是“如何移除徽章应用内快捷方式图标?”。我可以看到问题。但是,您没有将代码放在这里,我们如何才能给出正确的答案。别太聪明了。
        • 阅读问题描述
        • 虽然此代码可以解决 OP 的问题,但最好包含关于您的代码如何解决 OP 问题的说明。这样,未来的访问者可以从您的帖子中学习,并将其应用到他们自己的代码中。 SO 不是编码服务,而是知识资源。此外,高质量、完整的答案更有可能获得支持。这些功能,以及所有帖子都是独立的要求,是 SO 作为一个平台的一些优势,使其与论坛区分开来。您可以编辑以添加其他信息和/或使用源文档补充您的解释。
        【解决方案6】:

        在您的 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);
        
        
            }
        

        【讨论】:

        【解决方案7】:
        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的徽章?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-10-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多