你能强制广播来更新小部件吗?

发布于 2024-12-29 18:38:12 字数 200 浏览 2 评论 0原文

我几乎完成了我的第一个应用程序,一个电池小部件的制作,一切都运行得很好。唯一困扰我的是,我有一个广播接收器,当电池电量发生变化时,它会更新小部件,但是当我第一次将小部件添加到主屏幕时,它会等待电池电量/状态发生变化。 (插入或拔出设备也会更新它)。将意图过滤器更改为发送广播的其他方式不起作用,因为它不携带电池电量。我想知道是否有办法强制广播电池电量信息?

谢谢,菲尔。

I have almost finished making my first app, a battery widget and it all works fairly well. The only thing that is bothering me is that i have a broadcast reciver for when the battery level changes it updates the widget, but when i first add the widget to the home screen it then waits for the battery level / state to change. (plugging or uplugging the device updates it too). Changing the intent filter to other means of sending a boradcast doesn't work as it doesn't carry the battery level. I was wondering if there is a way for force a broadcast with the battery level information?

Thanks, Phil.

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

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

发布评论

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

评论(1

倚栏听风 2025-01-05 18:38:12

确保您正在调用

AppWidgetManager.updateAppWidget(ComponentName, RemoteViews);

小部件提供商的 onUpdate() 方法。创建小部件后,它应该自动运行 onUpdate()

Make sure you are calling

AppWidgetManager.updateAppWidget(ComponentName, RemoteViews);

in your onUpdate() method of your widget provider. When the widget is created it should automatically run onUpdate()

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