How to remove Pinned shortcuts after uninstalling app

361 Views Asked by At

I've added a shortcut to home screen using this code. It works fine but when I uninstall the app, added shortcuts are not removed automatically.

    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.parse("https://some.url/path"); 
    shortcutIntent.setData(uri);

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "name");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 
                      Intent.ShortcutIconResource.fromContext(context, 
                                          R.mipmap.ic_launcher));
    addIntent.putExtra("duplicate", false); 
    addIntent.setAction(ACTION_INSTALL_SHORTCUT);
    context.sendBroadcast(addIntent);

Am I missing something obvious?
Any help much appreciated.

0

There are 0 best solutions below