Remove the app icon from the pinned shortcut android

2k Views Asked by At

After 8 android, my application icon appears on the shortcuts.

enter image description here

I know that this was added specially to informing the user which app has created the shortcut.

Here is the code that is currently being used to create the icon.

   ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
    BitmapDrawable bd = (BitmapDrawable) ic;
    if (shortcutManager.isRequestPinShortcutSupported()) {
        Intent shortcutInfoIntent = new Intent(context, MainActivity.class);
        shortcutInfoIntent.setAction(Intent.ACTION_VIEW);
        shortcutInfoIntent.putExtra("pckg", pck);

        ShortcutInfo info = new ShortcutInfo.Builder(context, "iconId")
                .setIcon(Icon.createWithBitmap(bd.getBitmap()))
                .setShortLabel(label)
                .setIntent(shortcutInfoIntent)
                .build();

        PendingIntent shortcutCallbackIntent = PendingIntent.getBroadcast(context, 0, new Intent(context, MyReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);

        shortcutManager.requestPinShortcut(info, shortcutCallbackIntent.getIntentSender());
    }

I know that this is a fairly popular problem, but no one has provided a normal solution. But I need to take it away somehow

I'm sure that this is possible because it is implemented in x icon changer, where icons are created without these badges.

Please write all your ideas how to fix it

2

There are 2 best solutions below

3
On

I'm sure that this is possible because it is implemented in x icon changer, where icons are created without these badges.

They use app widgets for that. See the "ABOUT THE WATERMARK" in the Play Store listing that you linked to.

Please write all your ideas how to fix it

Write an app widget.

2
On

Apparently using the recommended shortcutManager.createShortcutResultIntent() will cause displaying app icon at the corner of the shortcut it created, but the deprecated Intent.EXTRA_SHORTCUT_INTENT way still works and there won't be an app icon in the created shortcut if you use this way and create your shortcut via the Widgets screen!

So the first step is to make your shortcut show on the Widgets screen. To make do this, ensure <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> is in your AndroidManifest.xml file, and create an activity that filter <action android:name="android.intent.action.CREATE_SHORTCUT"/>. The manifest file will look like this.

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

    <application
        ...>

        ...
        <activity
            android:name=".shortcuts.YourShortcut"
            android:label="@string/shortcut_name"
            android:icon="@mipmap/ic_launcher"
            android:exported="true"
            ...>
            <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    ...

In your activity, you'll need to create a shortcut. Normally we use setResult() with RESULT_OK as result code and the shortcutManager.createShortcutResultIntent() to create the intent for the 2nd argument, which will cause the app icon displayed in the corner of the shortcut. To avoid the shortcut icon, we can create the intent manually with the deprecated Intent.EXTRA_SHORTCUT_INTENT type. Something like:

    fun onOpen() {
        // things to do when user click the shortcut...
    }

    private fun setupShortcut() {
        val intent = Intent().putExtra(Intent.EXTRA_SHORTCUT_INTENT, Intent(this, this::class.java)) // we use this::class.java here, then clicking the shortcut will trigger onOpened()
                .putExtra(Intent.EXTRA_SHORTCUT_NAME, shortLabel)
                .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, iconResource));

        setResult(
            RESULT_OK,
            intent
        )
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (intent.action == Intent.ACTION_CREATE_SHORTCUT) {
            setupShortcut()
        } else {
            onOpened()
        }
        finish()
    }

Once we did these, you can see the shortcut appears on the Widgets screen. When the user drags the icon to the launcher, there will also not show the application icon in the corner.

Please note that the actual behavior may still be different when using a different launcher (it may not work under some launcher). The above code is tested with Pixel Launcher and Microsoft Launcher under Android 11 and Android 12.