Home > Enterprise >  Android Home Screen App Icon With Unwanted Mini-Icon Badge
Android Home Screen App Icon With Unwanted Mini-Icon Badge

Time:07-31

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?

enter image description here

The EyeSee icon is the one for my app. 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.

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

CodePudding user response:

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...". The larger icon is the icon for the shortcut. The smaller icon ("badge") in the lower right is the icon for the app (i.e., 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.

  • Related