Saturday, June 2, 2012

To send SMS in android


To send SMS from an android app we need to include the SEND_SMS permission in the android manifest file.

<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
   
The code snippet to send an SMS is

private void sendSMS(String phonenumber, String message)
{       
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phonenumber, null, message, null, null);       
}

Here, SmsManager.getDefault() is the static method available with SmsManager class and we can call this method to send sms from or app. To use this function we need to import SmsManager class using “import android.telephony.gsm.SmsManager;”

No comments:

Post a Comment