Send SMS from Android Application

Send SMS from Android Application

Hello people, It has been a while I haven’t posted anything about Android. Here I am with the new post about Send SMS from Android Application

Before We begin let me tell you there are two ways to send SMS from Android Application. They are :

  1. Using Native SMS Composer
  2. Using SmsManager API

Send SMS from Android Application Using Native SMS Composer

It’s the Easiest way to send SMS from Android Application. Make a function as follows:

In Java:

public void sendSMS()
{
    Uri uri = Uri.parse("smsto:12346556");
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    intent.putExtra("sms_body", "Here goes your message...");
    startActivity(it);
}

In Kotlin:

fun sendSMS()
{
    val uri = Uri.parse("smsto:12346556")
    val intent = Intent(Intent.ACTION_SENDTO, uri)
    intent.putExtra("sms_body", "Here goes your message...")
    startActivity(it)
}

Send SMS from Android Application Using SmsManager API

The second way of send SMS from Android Application is using SmsManager API.

In Java

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);

In Kotlin

val smsManager = SmsManager.getDefault() as SmsManager
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null)

SmsManager API needs SEND_SMS permission. Add permission to the manifest file:

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

Bonus

Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content"); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

That’s how Sending SMS from Android Application work. Thank you. Comment for doubts.

Happy coding!!!

Adam Brown
Please follow and like us:

Leave a Comment