HOW TO SEND SMS IN ANDROID? EXPLAIN WITH EXAMPLE.

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
 511  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    How to send SMS in android? Explain with example.

    If you want to send the SMS programmatically then follow the following steps.


    Take a button on activity_main.xml file as follows.

    <Button android:id="@+id/btnSendSMS" 
                 android:layout_width="wrap_content" 
                 android:layout_height="wrap_content" 
                 android:layout_centerHorizontal="true" 
                 android:layout_centerVertical="true" 
                 android:onClick=”sendmySMS” 
                 android:text="sendSMS" />

    According to above code when user clicks the button sendmySMS method will be called. sendmySMS is user defined method.

    In the AndroidManifest.xml file, add the following statements

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

    Now we write the final step. Write the given below method in MainActivity,java file

    publicvoidsendmySMS(View v)
    {
    SmsManager sms = SmsManager.getDefault(); 
    sms.sendTextMessage("5556", null, "Hello from MindStick", null, null);
    }

    In this example we have used two emulator. On the first Android emulator (5544), click the Send SMSbutton to send an SMS message to the second emulator(5546).

      Modified On May-28-2015 11:55:32 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!