【问题标题】:How can i get a list of my application's widgets that are active on the user's homescreen?如何获取在用户主屏幕上处于活动状态的应用程序小部件的列表?
【发布时间】:2012-11-20 00:14:39
【问题描述】:

来自文档:

AppWidgetManager.getAppWidgetIds(ComponentName provider) 获取已绑定到给定 AppWidget 提供程序的 appWidgetId 列表。

这将返回一个小部件 ID 列表,其中包括已从主屏幕删除的小部件。除了跟踪添加/删除事件和将我自己的列表主化以检索此信息之外,还有其他方法吗?

【问题讨论】:

    标签: android


    【解决方案1】:

    这是我的一些代码,如果你仍然需要它,它可以工作。

    private void updateWidget() {
        // We want to make sure the widget is always up to date.
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext());
    
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, Widget.class));
        if(appWidgetIds.length > 0) {
            new Widget().onUpdate(this, appWidgetManager, appWidgetIds);
        }
    }
    

    你可以在那里看到我是如何获得我需要的所有 id 的。然后在这里我从一个活动更新我的小部件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-18
      • 1970-01-01
      • 2020-05-05
      • 2012-05-30
      • 1970-01-01
      • 2013-12-09
      • 2017-04-22
      • 2011-06-11
      相关资源
      最近更新 更多