Friday, January 4, 2013

Sending SMS messages

Hi all,
in Android there are two ways to send SMS messages.
The first is to delegate the send action to SMS application by intent:
 
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "Content of the SMS goes here..."); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

The second way is to use the SmsManager (added in API level 4):

//---sends an SMS message to another device---
    private void sendSMS(String phoneNumber, String message)
    {        
        PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, SMS.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    }

To use the second method you need to add the permission to the manifest, because you send the message directly


3 comments :

  1. I absolutely feel ecstatic when I find articles relevant to my work and my subject.
    funny sms

    ReplyDelete
  2. w0o0 great article and the expression way of describing your services is cool, i like that and wish you all the best , God bless you, thank for sharing this great information with us

    small business outsourcing

    ReplyDelete
  3. You certainly deserve a round of applause for your post and more specifically, your blog in general. Very high quality material.
    healthcare payer bpo

    ReplyDelete