I have been trying to (ADD and then) REMOVE my APP's shortcut from HOME-SCREEN. ADDING a shortcut works perfectly however I'm not able to remove the shortcut I've created using below code.
public void setupShortCut(boolean create) {
shortcutIntent = new Intent();
shortcutIntent.setClassName("com.abc.xyz", "XYZActivity");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
Intent intentShortcut = new Intent();
intentShortcut.putExtra("android.intent.extra.shortcut.INTENT", shortcutIntent);
intentShortcut.putExtra("android.intent.extra.shortcut.NAME", getResources().getString(R.string.app_name));
intentShortcut.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", icon);
if(create) {
intentShortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
} else {
intentShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
}
sendBroadcast(intentShortcut);
}
Please suggest where am I going wrong?
EDIT 1:
I have required permission in my Manifest file:
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /