开发者

Update AppWidget from within program?

I need to update my AppWidget when my main activity pauses. I tried using the following code in my main activity's onPause():

super.onPause();
AppWidgetManager manager = AppWidgetManager.getInstance(this);
int[] a = manager.getAppWidgetIds(new ComponentName(this, "WidgetProvider"开发者_JAVA技巧));
new WidgetProvider().onUpdate(this, manager, a);

When I call this code, however, a is empty. What am I doing wrong?


I use this code to update my AppWidget:

AppWidgetManager manager = AppWidgetManager.getInstance(this);
int[] a = manager.getAppWidgetIds(new ComponentName("my.pkg", "WidgetProvider"));
List<AppWidgetProviderInfo> b = manager.getInstalledProviders();
for (AppWidgetProviderInfo i : b) {
    if (i.provider.getPackageName().endsWith("pkg")) {
        a = manager.getAppWidgetIds(i.provider);
    }
}
new WidgetProvider().onUpdate(this, manager, a);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜