Check Widget is Placed on Android Screen

Jeff picture Jeff · Jan 12, 2012 · Viewed 8.6k times · Source

Can someone tell me how to check that my widget have been placed on the homescreen?

I have some code in my app that should run only if the widget is placed on the homescreen.

Answer

Waza_Be picture Waza_Be · Apr 26, 2013

Just saying, but...

    int ids[] = AppWidgetManager.getInstance(this).getAppWidgetIds(new ComponentName(this,MyAppWidgetProvider.class));

    Toast.makeText(this, "Number of widgets: "+ids.length, Toast.LENGTH_LONG).show();