Home > Language Reference > Classes

Sms Class

  + Object
    + Sms

Description

The SMS class represents a SMS. It is used to send and receive short messages with the Telephony class. This class is instantiable, cloneable and derivable.

Sending messages

To send a message, instantiate a SMS class and set its Message and PhoneBook members. You can optionaly specify an expiration time in the Validity property. Then, pass this class to the SendSMS method of the Telephony class. For example:

Private Sub Button1_Click()
  Dim t As New Telephony
  Dim s As New Sms
  
  s.PhoneBook=New PhoneBook
  s.PhoneBook.Number="123456789"
  s.Message="Sample text"
  t.SendSMS s
End Sub

The system takes care of splitting long messages into segments of 160 characters each.

Receiving messages

To be notified of incoming messages, you first have to register for the hbServiceSMS telephony notifications using the RegisterNotify method of the Telephony class. Then handle the PhoneEvent event: when the hbPhoneEvtMessageInd notification is raised, the objParams parameter of the event is a SMS class whose Message, PhoneBook and Date members respectively contain the message body, the phone number of its sender, and the date of reception. For example, you could write in your main application class:

Private Sub Application_SyncNotify()
  Dim t As New Telephony

  ' Register for the SMS notifications when the application
  ' is installed through HotSync.
  t.RegisterNotify hbServiceSMS
End Sub

Private Sub Application_NormalLaunch()
  Dim f As New frmMain

  ' Simulate a SyncNotify event in case the application
  ' was not installed through HotSync, then open the main
  ' form.
  Application_SyncNotify
  f.Show hbFormModeless+hbFormGoto
End Sub

Private Sub Application_PhoneEvent(ByVal eCode As HbPhoneEvents, ByVal objParams As Object, ByRef bAcknowledge As Boolean)
  Dim s As Sms

  If eCode=hbPhoneEvtMessageInd Then
    s=Sms(objParams)
    MsgBox "New message from :" & s.PhoneBook.Number
  End If
End Sub

Note this is an oversimplified sample. In a realistic application, you should add some error checking to handle the case the application is run on a device that does not support the Telephony class, and you should not open a message box from the PhoneEvent handler. Instead, you should store the message in your database and set an alarm to launch your application later, when it is safe to open a blocking UI.

Members

MembersDescription
Date Reception date.
Message Message text.
PhoneBook Recipient or sender of a SMS.
Validity Validity period of a SMS.
Inherited from ObjectDescription
ClassID Returns the type identifier corresponding to the actual class of the object.
Implements Determines whether the object implements the features of a given class.
Iterate Event raised to iterate over the elements of a container object.
Recipient Recipient of events sent by the object.
Serialize Event raised to serialize the object content into a stream.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A