Android Tutorial

(avery) #1
Android Tutorial 401

Using SMS

SMS usage has become ubiquitous in the last several years.
Integrating messaging services, even if only outbound, to an
application can provide familiar social functionality to the user. SMS
functionality is provided to applications through the
android.telephony package.

Screen showing formatting results after entering only digits.

Gaining Permission to Send and
Receive SMS Messages

SMS functionality requires two different
permissions, depending on if the
application sends or receives messages.
The following XML, to be placed with
Android Manifest .xml, shows the
permissions needed for both actions:
<uses-permission
android:name=”android.permission.SEND_SMS”/>
<uses-permission
android:name=”android.permission.RECEIVE_SMS”
/>

Sending an SMS

To send an SMS, an application first needs to get an instance of the
SmsManager. Unlike other system services, this is achieved by
calling the static method get Default() of SmsManager:

final SmsManager sms = SmsManager.getDefault();

Free download pdf