RegisterNotification
method registers the widget to receive notifications of new incoming messages. For each new message, the method returns the header information of that message. It is available only in asynchronous mode.
The following is an example for using RegisterNotification
:
Asynchronous
sms_id = messaging_handle.call('RegisterNotification', {'Type': u'NewMessage'}, callback=new_sms_callback)
where, new_sms_callback
is a user defined callback function.
The following table summarizes the specification of RegisterNotification
:
Interface | IMessaging |
Description | Registers for getting notification for new messages. |
Response Model | Asynchronous |
Pre-condition | Valid instance of IMessaging interface is instantiated. |
Post-condition | Nil |
Input Parameters
Input parameter specifies the request for notification of new messages. The object must contain the NotificationType
property (unicode string), and this property must contain the value NewMessage
.
|
Output Parameters
Output parameters contain the requested information. They also contain ErrorCode
, and ErrorMessage
if the operation fails.
|
Errors
The following table lists the error codes and their values:
|
Error Messages
The following table lists the error messages and their description:
|
Example
The following sample code illustrates how to register for a new message notification, send a SMS and then cancel the notification request, asynchronously:
import scriptext import e32 lock = e32.Ao_lock() messaging_handle = scriptext.load('Service.Messaging', 'IMessaging') def new_sms_callback(trans_id, event_id, output_params): if trans_id == sms_id and event_id == scriptext.EventCompleted: print "SMS received from" + output_params['ReturnValue']['Sender']) else: print "Error in callback" # Cancel notification request messaging_handle.call('CancelNotification', {'Type': u'NewMessage'}) lock.signal() # The callback 'new_sms_callback' will be called when a sms is received sms_id = messaging_handle.call('RegisterNotification', {'Type': u'NewMessage'}, callback=new_sms_callback) # Send SMS to self so that the notification callback is hit messaging_handle.call('Send', {'MessageType': u'SMS', 'To': u'12345678', 'BodyText': u'Hi self'}) lock.wait()
See About this document... for information on suggesting changes.