简体   繁体   English

Android 主屏幕应用程序图标与不需要的迷你图标徽章

[英]Android Home Screen App Icon With Unwanted Mini-Icon Badge

After adding code that populates the device's home screen with a shortcut icon for my app, the icon appears as an aliased icon, with the main icon I'm trying to install on the home page and a mini version of the icon that's some sort of badge at the lower-right corner of my icon.在添加了使用我的应用程序的快捷方式图标填充设备主屏幕的代码后,该图标显示为别名图标,我尝试在主页上安装主图标以及某种迷你版图标我图标右下角的徽章。 Does anyone know how to prevent this badge from being displayed?有谁知道如何防止显示此徽章?

在此处输入图像描述

The EyeSee icon is the one for my app. EyeSee 图标是我的应用程序的图标。 Note another app's icon above mine has a mini badge that is not the same as it's main icon.请注意,我上面的另一个应用程序的图标有一个与主图标不同的迷你徽章。 I'd love to know how to create this alternate badge icon, but I'd be most grateful just to get rid of the mini alias icon - for now.我很想知道如何创建这个备用徽章图标,但我会非常感激只是暂时摆脱迷你别名图标。

Here's my code for creating the shortcut when OnCreate runs for the main activity.这是我在为主要活动运行 OnCreate 时创建快捷方式的代码。

private void createOrUpdateShortcut()
{
    SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);

    if(!isAppInstalled) 
    {
        Context appContext = getApplicationContext();

        Intent homeScreenShortCut= new Intent(appContext, MainActivity.class);
        homeScreenShortCut.setAction(Intent.ACTION_MAIN);
        homeScreenShortCut.putExtra("duplicate", false);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) 
        {
            homeScreenShortCut.setPackage(appContext.getPackageName());
            homeScreenShortCut.setClass(appContext, MainActivity.class);
            homeScreenShortCut.setClassName(appContext.getPackageName(), String.valueOf(MainActivity.class));

            ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
            assert shortcutManager != null;
            if (shortcutManager.isRequestPinShortcutSupported()) 
            {
                ShortcutInfo pinShortcutInfo =
                        new ShortcutInfo.Builder(this, "browser-shortcut-")
                                .setShortLabel(appContext.getResources().getString(R.string.app_name))
                                .setLongLabel(appContext.getResources().getString(R.string.app_name))
                                .setIcon(Icon.createWithResource(this,R.drawable.ic_launcher))
                                .setIntent(homeScreenShortCut)
                                .build();

                shortcutManager.requestPinShortcut(pinShortcutInfo, null);
                System.out.println("added_to_homescreen");
            } else {
                System.out.println("failed_to_add");
            }
        } else {
            if(shortcutReinstall) 
            {
                Intent removeIntent = new Intent();
                removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, homeScreenShortCut);
                String prevAppName = appPreferences.getString("appName", getString(R.string.app_name));
                removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, prevAppName);
                removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
                getApplicationContext().sendBroadcast(removeIntent);
            }

            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, homeScreenShortCut);
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
            addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            getApplicationContext().sendBroadcast(addIntent);
        }

        //Make preference true
        SharedPreferences.Editor editor = appPreferences.edit();
        editor.putBoolean("isAppInstalled", true);
        editor.putString("phoneLanguage", currentLanguage);
        editor.putString("appName", getString(R.string.app_name));
        editor.commit();
    }
}

Does anyone know how to prevent this badge from being displayed?有谁知道如何防止显示此徽章?

Generally speaking, that's not an option.一般来说,这不是一个选择。 The standard OS-supplied rendering of a pinned shortcut includes what you refer to as the badge, and there is no means of opting out of that badge.固定快捷方式的标准操作系统提供的呈现包括您所说的徽章,并且没有选择退出该徽章的方法。 Presumably, that is to help avoid apps from masquerading as other apps via these shortcuts.据推测,这是为了帮助避免应用程序通过这些快捷方式伪装成其他应用程序。

Note another app's icon above mine has a mini badge that is not the same as it's main icon请注意,我上面的另一个应用程序的图标有一个与主图标不同的迷你徽章

I assume that you refer to "Patio Motion...".我假设您指的是“Patio Motion ...”。 The larger icon is the icon for the shortcut .较大的图标是快捷方式的图标。 The smaller icon ("badge") in the lower right is the icon for the app (ie, what shows up in Settings and elsewhere).右下角较小的图标(“徽章”)是应用程序的图标(即显示在设置和其他地方的图标)。

In your case, you appear to have set the shortcut icon to be the same as your launcher icon, which is why you have this duplicate effect.在您的情况下,您似乎已将快捷方式图标设置为与启动器图标相同,这就是您具有这种重复效果的原因。 Use a different icon for the shortcut, ideally one that represents the action being taken by that shortcut.为快捷方式使用不同的图标,最好是代表该快捷方式正在执行的操作的图标。

As it stands, it seems like your shortcut is simply to launch your app, which is not what shortcuts are for.就目前而言,您的快捷方式似乎只是启动您的应用程序,这不是快捷方式的用途。 Most users can put a launcher icon on their home screen without the need for your app to publish a shortcut.大多数用户可以在他们的主屏幕上放置一个启动器图标,而无需您的应用发布快捷方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式在主屏幕应用程序图标android中设置徽章编号? - How set badge number in home screen app icon android programatically? 使用LauncherShortcuts在主屏幕上显示Android App图标 - Android App Icon on Home Screen using LauncherShortcuts Android隐藏的应用程序图标出现在主屏幕上 - Android hidden app icon appear on home screen 科尔多瓦android应用程序不显示主屏幕上的图标 - Cordova android app not showing icon on home screen 为什么我的应用程序徽标图标在主屏幕上没有显示? - Why My Application Badge Icon in home Screen Not showing? 如何在Android的主屏幕上的我的应用程序图标上显示通知计数 - How to show Notification Count on My App Icon on Home Screen in Android 在android中的app图标上添加通知徽章 - adding notification badge on app icon in android 以编程方式安装Android应用程序时如何在主屏幕上添加图标? - How to add a icon on home screen while installing an android app programatically? 如何在主屏幕 android 上添加应用程序图标(react-native)? - How to add icon of the app on the home android screen (react-native)? 应用程序启动器图标未显示在 Android 电视的主屏幕中 - app launcher icon is not showing in home screen of android tv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM