Android – Sending SMS from android application – Method 1

By -

Today I am going to discuss about to send SMS from your android application.

Basically there are 2 ways by which we can send sms:

  1. Open native SMS composer
  2. write your message and send from your android application
So here I am going to write about the 1st method i.e. Open native SMS Composer.

(For your information, Method 2 – Send SMS from your application)

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
	android:id="@+id/relativeLayout1"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	xmlns:android="http://schemas.android.com/apk/res/android">

        <Button
        	android:id="@+id/btnSendSMS"
        	android:layout_height="wrap_content"
        	android:layout_width="wrap_content"
        	android:text="Send SMS"
        	android:layout_centerInParent="true"
        	android:onClick="sendSMS">
        </Button>
</RelativeLayout>

SendSMSActivity

package com.technotalkative.sendsms;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class SendSMSActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     }

    public void sendSMS(View v)
    {
        String number = "12346556";  // The number on which you want to send SMS
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));
    }
   /* or
    public void sendSMS(View v)
     {
	Uri uri = Uri.parse("smsto:12346556");
    	Intent it = new Intent(Intent.ACTION_SENDTO, uri);
    	it.putExtra("sms_body", "Here you can set the SMS text to be sent");
    	startActivity(it);
     } */
}

In this method, we doesn’t require SEND_SMS permission inside the AndroidManifest.xml file

CEO & Co-Founder at SolGuruz® | Organiser @ GDG Ahmedabad | Top 0.1% over StackOverflow | 15+ years experienced Tech Consultant | Helping startups with Custom Software Development

Loading Facebook Comments ...
Loading Disqus Comments ...