I need to find any AppWidget id to test some features. The code to do this:
List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders();
for (int i = 0; i < infos.size(); i++) {
int ids[] = mAppWidgetManager.getAppWidgetIds(infos.get(i).provider);
if (ids.length != 0) {
Log.d("TAG", "Found non-zero-length provider!");
id = ids[0];
info = infos.get(i);
break;
}
}
But ids[] length is always 0! Why and how to fix it?
Update: I have added this line to the loop's beginning:
Log.d("TAG", provider.getPackageName() + "; " + provider.getClassName());
And it prints:
D/TAG ( 5686): Providers count: 12
D/TAG ( 5686): com.andrew.apollo; com.andrew.apollo.app.widgets.AppWidget11
D/TAG ( 5686): com.andrew.apollo; com.andrew.apollo.app.widgets.AppWidget41
D/TAG ( 5686): com.andrew.apollo; com.andrew.apollo.app.widgets.AppWidget42
D/TAG ( 5686): com.android.browser; com.android.browser.widget.BookmarkThumbnailWidgetProvider
D/TAG ( 5686): com.android.calendar; com.android.calendar.widget.CalendarAppWidgetProvider
D/TAG ( 5686): com.android.contacts; com.android.contacts.socialwidget.SocialWidgetProvider
D/TAG ( 5686): com.android.deskclock; com.android.alarmclock.AnalogAppWidgetProvider
D/TAG ( 5686): com.android.email; com.android.email.provider.WidgetProvider
D/TAG ( 5686): com.android.gallery3d; com.android.gallery3d.gadget.PhotoAppWidgetProvider
D/TAG ( 5686): com.android.quicksearchbox; com.android.quicksearchbox.SearchWidgetProvider
D/TAG ( 5686): com.android.settings; com.android.settings.widget.SettingsAppWidgetProvider
D/TAG ( 5686): com.android.vending; com.android.vending.MarketWidgetProvider
So, it seems to be OK, but I still can't get id's of this widgets.
Make sure that ComponentName
you use to get AppWidgetManager
matches the widget provider in the manifest. If it doesn't, you'll get an empty list (ids.length = 0, the loop won't execute).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With