2

I have code to make a shortcut of my application on the home screen when the user firsts opens the application. Is it possible to make it so that the application sets it so that when the user opens the application the shortcut is replaced with the widget?

This is the code that I am using to set the shortcut

Intent shortcutIntent = new Intent();
    shortcutIntent.setClassName(".BatteryWidget", "SampleIntent");
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra("someParameter", "HelloWorld");

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);


    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    this.sendBroadcast(addIntent);

-Thanks in advance.

Christian
  • 958
  • 5
  • 23
  • 52

1 Answers1

2

No, adding widgets to the homescreen doesn't work without user interaction. Let alone deleting/replacing a shortcut.

Mark
  • 520
  • 1
  • 7
  • 21
  • Yeah thanks for the reply. i actually found that out on my own i guess i should have posted that – Christian Jul 20 '11 at 23:58
  • @Mark Could you please point me to the documentation? Just in case. Thank you in advance :-) –  Apr 20 '12 at 02:13
  • There is neither doc which says that it works nor that is doesn't. There is just no API method to do that. And it also makes sense, cause maybe you can replace an icon with a 1x1 widget (in terms of size) but many widgets are bigger than that and require the user to choose a homescreen with enough space for that. – Mark Apr 25 '12 at 13:33