Test Script

Saturday, December 7, 2013

How To Send SMS In Android

Hi guys, today in this tutorial we will be looking at how you can send SMS in Android through your next killer app you are designing.



You can use two methods to send out SMS :

1. SmsManager API

2. Built In SMS Application

Using the SmsManager API - using this API you can send SMS directly from within your apps. Here is how

SmsManager smsManager = SmsManager.getDefault();
 smsManager.sendTextMessage("1234567890", null, "SMS Text goes here!", null, null);


That's it, its that simple !
1.  The first parameter is where you send the mobile number to which you wish to send the SMS to.
2.  The 3rd parameter contains the text of the SMS to be sent out.
3.  We create an instance of the SmsManager and using the sendTextMessage method we send out the SMS.
This will send the message using the user's credits, so it is always advised to confirm with the user once before sending out the SMS.

Using the Built-In SMS App - using this method you can redirect the user from your application to the default Messaging app in the device where the user can proceed further as needed.

Here is how we can invoke the default SMS app :

Intent sendIntent = new Intent(Intent.ACTION_VIEW);
 sendIntent.putExtra("sms_body", "The SMS text goes here!"); 
 sendIntent.setType("vnd.android-dir/mms-sms");
 startActivity(sendIntent);

Here is what we did :

1.  Create a new intent with the action as Intent.ACTION_VIEW
2.  Set the body of the SMS using the putExtra method, make sure you put the key as " sms_body".
3.  Set the type to  "vnd.android-dir/mms-sms".
4.  Start the activity.

The user will now be redirected to his default/chosen SMS app. Also for both the above methods to work you need to have the Send SMS permission so add the following permission in the Android Manifest :



That's all there is to send out a SMS through your app. Also if your targeting devices on Android 4.4 and above make sure to check this link :  Android 4.4 SMS Changes

Feel free to drop me any comments/queries. 

6 comments:

  1. Quite nice tutorial and I have just tried it and it truly works. Well I am also thinking to start utilizing the easy to use app for sending bulk SMS to the potential audience. There are many app but I am not able to find a good option that is appropriate for real estate text marketing. Was just wondering if you can help me regarding it!

    ReplyDelete
  2. Nice Article, Message Sender App is a multiple SMS sending tool from Multiple Android phones through a single platform at once bulk sms sender

    ReplyDelete
  3. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. Small Business Marketing

    ReplyDelete
  4. If you are looking for more information about flat rate locksmith Las Vegas check that right away. Text Marketing Autoresponder

    ReplyDelete
  5. Nice article. the best way to outreach to potential customers is to directly connect Best sms marketing software

    ReplyDelete
  6. Such a great information, thanks for sharing with us.Android Bulk SMS Sender

    ReplyDelete

UA-42774700-1 Twitter Bird Gadget