Reputation: 1120
I'm trying to read the available home screen widgets list on Android. I can populate a grid using the available applications list using
Intent myIntent = new Intent(Intent.ACTION_MAIN, null);
myIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appsInfo = MyActivity.getPackageManager().queryIntentActivities(myIntent, 0);
and than iterating through each ResolveInfo.
How can I do the same with available Home screen widgets? I'd like to populate a grid with the same list that appears keep touching the screen and choosing 'widget' from the appearing popup.
Upvotes: 8
Views: 8281
Reputation: 14213
As suggested by CommonsWare, here is the working code for extracting list of widgets
AppWidgetManager manager = AppWidgetManager.getInstance(this);
List<AppWidgetProviderInfo> infoList = manager.getInstalledProviders();
for (AppWidgetProviderInfo info : infoList) {
Log.d(TAG, "Name: " + info.label);
Log.d(TAG, "Provider Name: " + info.provider);
Log.d(TAG, "Configure Name: " + info.configure);
}
Various other values can be extracted, for more reference see AppWidgetProviderInfo
Upvotes: 14