如何识别 Glance App Widget 的多个实例

发布于 2025-01-14 18:33:44 字数 240 浏览 6 评论 0原文

我正在尝试创建一个显示有关硬件设备信息的小部件。 可以有多个这样的设备,用户将能够为不同的设备添加相同的小部件。 我正在寻找一种方法来了解应在 GlanceAppWidget.Content() 方法中显示哪些设备信息。在经典 Android Widget 中,可以通过检查传递给 update() 方法的 appWidgetId 来实现。乍一看,appWidgetId 是故意隐藏的,但我找不到替代解决方案。

有什么建议吗?

I am trying to create a widget which shows information about a hardware device.
There can be multiple of these devices and user will be able to add same widget for different devices.
I am looking for a way to understand which device information should be shown inside GlanceAppWidget.Content() method. In Classical Android Widgets it was possible by checking appWidgetId passed to update() method. At Glance appWidgetId is hidden intentionally but I could not find an alternative solution.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘世孤行 2025-01-21 18:33:44

当放置小部件来选择设备时,您可能会使用配置活动,对吗?

然后,您可以使用 GlanceID 将数据存储在该特定实例的状态 (updateAppWidgetState())。然后在内容中,您可以检索currentState以了解需要显示哪个硬件设备。

Probably you will use a configuration activity when the widget is placed to select the device right?

You can then use the GlanceID to store data in the state of that specific instance (updateAppWidgetState()). Then inside the Content you can retrieve the currentState to know which hardware device needs to be shown.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文