Background
Starting with Android O, you can create pinned shortcuts that (on supported launchers) show a dialog to confirm their creation:
ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(context, uniqueShortcutId) .setShortLabel(label) .setIntent(shortcutIntent) .setLongLabel(label) .setIcon(IconCompat.createWithBitmap(bitmap)) .build(); ShortcutManagerCompat.requestPinShortcut(this, pinShortcutInfo , null);
Docs:
https://developer.android.com/reference/android/content/pm/ShortcutManager.html https://developer.android.com/guide/topics/ui/shortcuts.html
Problem
Sometimes the attached shortcut is no longer relevant. For example, it indicates that it no longer exists.
In this case, I want to delete it.
What i tried
I thought this was possible with the following code, but it is not, because these are probably dynamic shortcuts, something else:
ShortcutManager shortcutManager = (ShortcutManager) getSystemService(SHORTCUT_SERVICE); final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts(); final ArrayList<String> shortcutIdsToRemove = new ArrayList<>(); for (ShortcutInfo pinnedShortcut : pinnedShortcuts) { final Intent pinnedShortcutIntent = pinnedShortcut.getIntent(); shortcutIdsToRemove.add(pinnedShortcut.getId()); } shortcutManager.removeDynamicShortcuts(shortcutIdsToRemove);
Question
How to delete deleted shortcuts? Is it possible?
Update: It seems this is not possible, as Google mentioned here .
So far, this API seems very limited to me, as it has so many flaws:
- The created icon image cannot be created from the resource identifier.
- On the launch bar, the created icon has a small icon for the application that created it.
- The icon cannot be deleted using the API (only disabled), so if you created one that points to another application and this application was deleted, you cannot delete it.
- Creation cannot be in the background, as this requires a confirmation dialog box. It also cannot be created in a package. Only one after another.
- All attached shortcuts created by your application will be deleted if your application has been deleted.
So now my question is:
Is there a way to create and remove a shortcut using the previous API using the adb command, with the root, if necessary?
Is it possible to remove specific pinned shortcuts using the adb command, with the root, if necessary?
source share