Step by step how to example send SMS in android

Asked By 10 points N/A Posted on -
qa-featured

I want to create send SMS in my application.

I am looking for a step by step how to, is there any code example sends sms in android or tutorial where I can follow? 

SHARE
Answered By 0 points N/A #151563

Step by step how to example send SMS in android

qa-featured

There are 2 ways to send sms in andriod:

1. Using built-in SMS Application

  • Set the action to ACTION_VIEW
  • Set the mime type to vnd.android-dir/mms-sms
  • Add the text to send by adding an extra String with the key sms_body
  • Add the phone number of the recipient to whom you wish to send the message by adding an extra String with the key address

Code to send a SMS built-in function

Intent sendIntent = new Intent(Intent.ACTION_VIEW);

                sendIntent.putExtra("sms_body", "default content");

                sendIntent.setType("vnd.android-dir/mms-sms");

                startActivity(sendIntent)

2. Using SMsmessage API

Include the following permission in your AndroidManifest.xml file

<uses-permission android:name="android.permission.SEND_SMS" />

Import the package –

import android.telephony.SmsManager;

code:

public void sendSMS() {

    String phoneNumber = "0123456789";

    String message = "Hello World!";

    SmsManager smsManager = SmsManager.getDefault();

    smsManager.sendTextMessage(phoneNumber, null, message, null, null);

}

The method sendTextMessage of class SmsManager sends a text based SMS.

Related Questions