RegisterNotification()

Description:

The RegisterNotification method registers the Flash Lite application to receive notifications of new incoming messages. For each new message, the method returns the header information of that message.

This is an asynchronous method.

Syntax:

RegisterNotification(parameters:Object, callback:Object):Object

Arguments:

  • parameters:

    This is an object that specifies the request for notification of new messages. The object must contain the Type property (string), and this property must contain the value "NewMessage":

    parameters.Type = "NewMessage";
  • callback:

    The callback argument is the name of the method that is executed when RegisterNotification 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 RegisterNotification method returns an object that contains the initial return value for the asynchronous call it started (see the following table). The actual notification information is returned by the callback method in the ReturnValue property of its result object. The returned information is described in section Returned notification information.

Table: Return value properties for RegisterNotification

Property

Description

Value

TransactionID

This is a number used as an identification to match transactions started with a RegisterNotification 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:

RegisterNotification retrieves new message updates until cancelled with CancelNotification (or Cancel). You can therefore have only one RegisterNotification call (one instance) pending or in use at any given time.

Example code:

The following sample code illustrates how to registers for receiving notifications for new messages:

import com.nokia.lib.Service;
var messaging = new Service("Service.Messaging", "IMessaging");
var inParams = {Type:"NewMessage"};
messaging.RegisterNotification(inParams,onNotify);
function onNotify(transactionID:Number, eventID:String, outParam:Object) {
  if (outParam.ErrorCode == 0) {
    // New message got!
    var messageheader = outParam.ReturnValue;
    var sender = messageheader.Sender;// Message sender information
    var messageId = messageheader.MessageId;// Message indentifier
  } else {
    var errorId = outParam.ErrorCode;
  }
}