Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the installed widget list?

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.

like image 365
lorenzoff Avatar asked Nov 25 '10 11:11

lorenzoff


People also ask

Where is the widgets listing?

First, touch hold an open space on your home screen. You'll see an option at the bottom of the screen to view the widgets drawer, which is where they dwell until summoned for duty. Select the widgets drawer, then browse through the choices.

Where are Android widgets stored?

The widgets are usually stored within the application apk. As far as the power controls, my guess would be framework-res. apk in /system/framework...

How do I add widgets to the launcher?

Long press on an empty area of your home screen where you want to add a widget. From the menu that shows up, tap Widgets. Tap and hold the widget that you'd like to add to your home screen. All the available widget sizes will also be shown to you in this very panel.


2 Answers

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

like image 160
Akhil Jain Avatar answered Oct 22 '22 17:10

Akhil Jain


Call getInstalledProviders() on an AppWidgetManager.

like image 38
CommonsWare Avatar answered Oct 22 '22 17:10

CommonsWare