I am trying to add/remove shortcut for my app. The "add" code works
perfect. But removing works only if I run it at the same app instance it
was created. If I create the shortcut, then restart app and finally execute
the "remove" code it fails (don't remove the icon).
This is my code:
public static void add(Class<? extends Activity> activity, String name,
Bitmap icon) {
Context context = ...;
icon = scaleIcon(context, icon);
Intent shortcutIntent = new Intent(context, activity);
shortcutIntent.setAction(Intent.ACTION_MAIN);
int flags = Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED;
shortcutIntent.setFlags(flags);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
addIntent.setAction(SHORTCUT_INSTALL);
context.sendBroadcast(addIntent);
}
public static void remove(Class<? extends Activity> activity, String name) {
Context context = ...;
Intent shortcutIntent = new Intent(context, activity);
shortcutIntent.setAction(Intent.ACTION_MAIN);
int flags = Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED;
shortcutIntent.setFlags(flags);
Intent removeIntent = new Intent(SHORTCUT_UNINSTALL);
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
context.sendBroadcast(removeIntent);
}
BTW, I couldn't find android docs about shortcuts. Thanks for helping me.
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/57fc3b1f-9394-4c54-9b04-ad6dbeb67dc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.