Android ShortcutManager Dynamic Launcher Shortcuts

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1")
    .setShortLabel("Web site") // Shortcut Icon tab
    .setLongLabel("Open the web site") // Displayed When Long Pressing On App Icon
    .setIcon(Icon.createWithResource(context, R.drawable.icon_website))
    .setIntent(new Intent(Intent.ACTION_VIEW,
                   Uri.parse("https://www.mysite.example.com/")))
    .build();

shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));

We can remove all dynamic shortcuts easily by calling :-

 shortcutManager.removeAllDynamicShortcuts();

We can update existing Dynamic Shorcuts by Using

shortcutManager.updateShortcuts(Arrays.asList(shortcut);

Please note that setDynamicShortcuts(List)is used to redefine the entire list of dynamic shortcuts, addDynamicShortcuts(List) is used to add dynamic shortcuts to existing list of dynamic shortcuts



Got any Android Question?