Broadcast
About the Broadcast API
Version compatibility
This feature is only available on Android devices running version 4.29.0 or newer versions of the JourneyApps Container.
The Broadcast
service is used to send data to and receive data from external Android apps using JavaScript.
The Broadcast service supports Android broadcast categories. Please see the action test and category test sections in the Android documentation on Intents and Intent Filters for more information on intent resolution.
Receiving Data
Use the register
function to receive data:
target
Broadcast.Target
Broadcast registration target.
target.action
string
Unique name used to identify the broadcasting event. This should correspond to the event name in your external application.
target.categories
string[]
Array of categories to register broadcast against.
callback
function
Function to be called as soon as a broadcast event is received. The function takes a single parameter, data
(object)
options
object
Optional object to specify options. Added in v21.2.1 of the JourneyApps Container and v4.78.2 of the JourneyApps Runtime.
options.background
boolean
Should Broadcasts trigger when the container is in the background. Defaults to true
e.g.
Sending Data
Use the trigger
function to send data:
target
Broadcast.Target
Listener target to broadcast to.
target.action
string
Unique name used to identify the broadcasting event. This should correspond to the event name in your external application.
target.categories
string[]
Array of categories for broadcast event.
eventData
object
Data sent to the external application. Note that eventData
should be an object.
e.g.
Finding out if the Broadcast API is supported
Use the getCapabilities
function to see whether the active device and JourneyApps Container supports the Broadcast API:
** Returns **: object
with a supported
field. This field will be true
if the active device and JourneyApps Container supports the Broadcast API and false
otherwise.
Other Usage Notes
Here are some other code examples that show how the Broadcast API can be used.
Registering a broadcast receiver:
Removing a single broadcast receiver registration:
Removing all broadcast receiver registrations:
Triggering a broadcast (eventData
must be an object):
eventData
must be an object):Last updated