Reputation: 854
I want to remove all the shortcuts on home screen of my app on a single event like button click. Is there any way to do this ? or at least get the display-names of all the shortcuts placed on home screen from my app ? ( I cant have it in any shared-prefs / db while creation of shortcuts because user can even do a 'clear-data' )
Upvotes: 0
Views: 790
Reputation: 28823
Try this:
appShortcutIntent = new Intent();
appShortcutIntent.setClassName("com.pkg.pkgname", "MainActivity");
appShortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
appIcon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
Intent intentDeleteShortcut = new Intent();
intentDeleteShortcut.putExtra("android.intent.extra.shortcut.INTENT", appShortcutIntent);
intentDeleteShortcut.putExtra("android.intent.extra.shortcut.NAME", getResources().getString(R.string.app_name));
intentDeleteShortcut.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", appIcon);
intentDeleteShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
sendBroadcast(intentDeleteShortcut);
And add this permission in manifest file:
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
Hope this helps.
(P.S: This will require the device to be rooted as far as I know.)
Upvotes: 1