THIS CONTENT DOWNLOAD SHORTLY

Objective

This example is using the device’s build-in SMS application to send out the SMS message.

 

You will get Final Output:

 

Step 1 Android Layout

Path: res >> layout >> main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >
 
    <EditText
        android:id="@+id/editTextSMS"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:gravity="top"
        android:hint="Enter Text Message"
        android:inputType="textMultiLine"
        android:lines="5" >
 
        <requestFocus />
    </EditText>
 
    <EditText
        android:id="@+id/edtNumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Enter Number"
        android:inputType="phone" />
 
    <Button
        android:id="@+id/buttonSend"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Send" />
 
</LinearLayout>
 

Step 2 SendSMSActivity.java

SendSMSActivity.java – Activity class to use build-in SMS intent to send out the SMS message.

public class SendSMSActivity extends Activity {
 
Button buttonSend;
EditText edtTextSMS, edtNumber;
 
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
 
buttonSend = (Button) findViewById(R.id.buttonSend);
edtTextSMS = (EditText) findViewById(R.id.editTextSMS);
edtNumber = (EditText) findViewById(R.id.edtNumber);
 
buttonSend.setOnClickListener(new OnClickListener() {
 
@Override
public void onClick(View v) {
 
try {
 
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", edtTextSMS.getText()
.toString());
sendIntent.putExtra("address", edtNumber.getText()
.toString());
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
 
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
 
}
});
 
}
}
 

Step 3 Add Permission into Manifest file

Add Permission into Manifest file.

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

I hope you enjoy this tutorial and it would be helpful to you. Got an Idea of Android App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Android App Development Company in India.

An entrepreneur who has founded 2 flourishing software firms in 7 years, Tejas is keen to understand everything about gaming - from the business dynamics to awesome designs to gamer psychology. As the founder-CEO of a company that has released some very successful games, he knows a thing or two about gaming. He shares his knowledge through blogs and talks that he gets invited to.