RegisterForNotification()

Description:

The RegisterForNotification method registers the client to receive data from one sensor channel.

This is an asynchronous method.

Syntax:

RegisterForNotification(parameters:Object, callback:Object):Object

Arguments:

  • parameters:

    This is an object that specifies the sensor channel to listen for data. For more information about the object properties and how to define them, see section Parameters for receiving sensor data.

  • callback:

    The callback argument is the name of the method that is executed when a RegisterForNotification call has results or status information to return. You must define this method separately. Follow the instructions in section Defining the callback handler for an asynchronous method to define the callback method.

Return value:

The RegisterForNotification method returns an object that contains the initial return value for the asynchronous call it started (see the following table). The actual sensor data is returned by the callback method in the ReturnValue property of its result object. The returned data is described in section Returned sensor data.

Table: Return value properties for RegisterForNotification

Property

Description

Value

TransactionID

This is a number used as an identification to match transactions started with the RegisterForNotification call to one or more calls it generates to callback.

 

ErrorCode

This is a number that specifies a predefined error code.

See Service API error codes.

ErrorMessage

This is a text string that describes the error.

Remarks:

  • RegisterForNotification retrieves sensor data until cancelled with Cancel.

  • Invoking the same call on the same sensor channel from the same user without cancelling the previous RegisterForNotification request results in an error, since the channel is already listening on the pre-registered notifications.

Example code:

The following sample code illustrates how to register for notification with a sensor channel to receive channel data:

import com.nokia.lib.Service;
var sensor = new Service("Service.Sensor", "ISensor");
var channelInfo = {ChannelId:channelId, ContextType:contextType, Quantity:quantity, ChannelType:channelType, Location:location, VendorId:vendorId, DataItemSize:dataItemSize, ChannelDataTypeId:channelDataTypeId}; // Valid values must be passed to Channelinfo
var inParams = {ListeningType:"ChannelData", ChannelInfoMap:channelInfo};
sensor.RegisterForNotification(inParams, onNotify);
function onNotify(transactionID:Number, eventID:String, outParam:Object) {
  if (outParam.ErrorCode == 0) {
    var channelData = outParam.ReturnValue;
    var deviceOrientation = channelData.DeviceOrientation;
  } else {
    var errorId = outParam.ErrorCode;
  }
};