Skip to content

voltmx.wearable Namespace Functions

The voltmx.wearable namespace provides the following functions.

voltmx.wearable.addCapabilityChangeListener Function


Adds a callback event handler function that monitors for changes to the status of paired devices, such the device becoming available or unavailable.

Syntax


voltmx.wearable.addCapabilityChangeListener(  
    capability,  
    onCapabilityChanged,  
    errorCallback);

Parameters

capability

A string that specifies the capability to look for on all of the paired devices.

onCapabilityChanged

A JavaScript function that receives the capable devices list and responds accordingly. The callback must have the following signature.

onCapabilityChanged(capability, nodes);

Where capability is a string that specifies the given capability for which callback function is called, and nodes is an array of JavaScript objects, each of which represents a device, or node, that is paired with the current device. The JavaScript objects each hold the following key-value pairs.

Key Value
displayName A string containing the name of the device.
nodeId A string that specifies a unique ID for the device.
isNearBy A Boolean value that is true if the device is nearby (within range), or false if not.

errorCallback

A callback event handler function that is invoked when there is an error. This callback function must have the following signature.

errorCallback(errorConst);

Where errorConst is a value from the Callback Result Constants.

Return Values

None.

Remarks

This function enables your app to see when devices that are paired with the current device become available or unavailable, or when the paired app gets installed or uninstalled.

Important: To call this function from the app that is paired with your watch app, you must set the compilation settings in  Volt MX Iris appropriately. For details, see Transmitting Data Between Paired Apps.

Example


function addCapabilityChangeListener()
{
    voltmx.wearable.addCapabilityChangeListener("capability_1", onCapabilityChanged, capabilityErrorCallback);
}

function onCapabilityChanged(capability, nodesArray)
{
    if (nodesArray.length > 0)
    {
        alert("nodes with capability " + capability + "  exists “ );
    }
    else
    {
        alert("no node is  connected with capability " + capability);
    }
}

function capabilityErrorCallback(errorConst)
{
    alert("error occured, errorConst = " + errorConst);
}

Platform Availability

Android Wear 2.0 or later.


voltmx.wearable.addForegroundDataItemListener Function


Receives data items when the app is in the foreground.

Syntax


voltmx.wearable.addForegroundDataItemListener(  
    onDataItemReceiver,  
    errorCallback);

Parameters

onDataItemReceiver

A callback event handler function that is invoked when data items are received from the paired device. The callback function passed through the onDataItemReceiver parameter must have the following signature.

onDataItemReceiver(path,payloadTable,nodeId);

Where path is the path string that the sending app on the pair device sent when it called the voltmx.wearable.putDataItem function, payloadTable is the JavaScript object containing the data payload that the sending app on the pair device sent when it called the voltmx.wearable.putDataItem function, and nodeId is the sending app's device identification ID.

errorCallback

A