5

I wrote a widget that sits on my home screen.

There is also a configuration activity which can be started from the widget or from the launcher.

When started from launcher, I don't have the widget id.

Is it possible to find it somehow?

The reason is that I want to send an update message from the activity to the widget.

Ran
  • 4,117
  • 4
  • 44
  • 70

1 Answers1

16

Something like this seems to work for me:

Context context = getApplicationContext();
ComponentName name = new ComponentName(context, MyWidgetProvider.class);
int [] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(name);
Bartek
  • 176
  • 1
  • 3
  • 1
    It works, but don't forget about phantom widgets. See extended solution here: http://stackoverflow.com/questions/17387191/check-if-a-widget-is-exists-on-homescreen-using-appwidgetid – zuko Jun 16 '15 at 10:12