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.
Use the
register
function to receive data:Broadcast.register(target, callback, options);
Parameter | Type | Details |
---|---|---|
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.
function callback(data) {
console.log("Received: " + JSON.stringify(data));
}
Use the
trigger
function to send data:Broadcast.trigger(target, eventData);
Parameter | Type | Details |
---|---|---|
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. | | |
{
"action": "START"
}
Use the
getCapabilities
function to see whether the active device and JourneyApps Container supports the Broadcast API:Broadcast.getCapabilities();
** 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.Here are some other code examples that show how the Broadcast API can be used.
var watchId;
function callback(data) {
console.log("Callback:", JSON.stringify(data));
}
var target = {
action: "com.example.action",
categories: [
"com.example.category.a",
"com.example.category.b"
]
};
watchId = Broadcast.register(target, callback);
Broadcast.deregister(watchId);
Broadcast.deregisterAll();
var target = {
action: "com.example.action",
categories: [
"com.example.category.a",
"com.example.category.b"
]
};
Broadcast.trigger(target, {foo: "bar", "name": "trigger"});
Last modified 1yr ago