🚀 [Feature Request] Enable Frequent Widget Updates via BroadcastReceiver
First and foremost, I want to express my sincere gratitude for your work on the react-native-android-widget library.
Description
Currently, the react-native-android-widget library offers two methods for updating widget:
-
updatePeriodMillis: This method schedules periodic updates but is limited to a minimum interval of 30 minutes, as per Android's restriction. -
requestWidgetUpdate: Allows manual updates when the app is activity However, for widgets that display real-time information such as clocks, timers, or live data feeds, these methods are insufficient due to their infrequency or reliance on the app being open.
Proposed Enhancement
Introduce support for updating widgets using BroadcastReceiver, enabling more frequent and responsive updates. This can be achieved by:
-
Listening to System Broadcasts: Register a
BroadcastReceiverto listen for system events likeACTION_TIME_TICK, which is broadcast every minute. This allows the widget to update in response to these event. -
Using
AlarmManager: Schedule regular updates by setting alarms that trigger theBroadcastReceiverat desired intervals, even when the app is not active -
Implementing
goAsync(): Within theonReceive()method of theBroadcastReceiver, usegoAsync()to perform asynchronous operations without blocking the main thread, ensuring smooth update.
References
Two out of the three provided references are dead links :)
I'm not sure if adding broadcast receivers should be a part of this library, since it adds more complexity and is not strictly related to widgets. Maybe it can be implemented in a different library, or as custom code.
What I might do is add a native helper in the library, that when called will call the JS widget task handler.
I just released 0.17.0 that implements this feature.
See https://saleksovski.github.io/react-native-android-widget/docs/update-widget#native-rnwidgetjscommunicationrequestwidgetupdate