Brian
Brian

Reputation: 326

How can i get a list of my application's widgets that are active on the user's homescreen?

From the docs:

AppWidgetManager.getAppWidgetIds(ComponentName provider) Get the list of appWidgetIds that have been bound to the given AppWidget provider.

This returns a list of widget ids including widgets that have been deleted from the homescreen. Is there a way besides tracking the add/delete events and mainlining my own list to retrieve this information?

Upvotes: 1

Views: 408

Answers (1)

MinceMan
MinceMan

Reputation: 7592

Here is a bit of my code which works if you still need this.

private void updateWidget() {
    // We want to make sure the widget is always up to date.
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext());

    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, Widget.class));
    if(appWidgetIds.length > 0) {
        new Widget().onUpdate(this, appWidgetManager, appWidgetIds);
    }
}

You Can see there how I am able to get all the id's I need. Then here I update my widget from an activity.

Upvotes: 2

Related Questions