Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art
Sending Single-Part or Multipart SMS MessagesBack to Android Cookbook Home | Up to Chapter: Telephone Applications

Author: Colin Wilcox ('NavaronUK')
In Published Edition? Yes
FormatLanguage: WikiFormat

Sending Single-Part or Multipart SMS Messages

Problem

A simple way to send either a single part or a multipart (handing the message concatenation UDH) from a single entry point

Solution

Use the SMSManager.

Discussion

public class SendSMS
{
	SMSManager iSMSManager = null;
	ArrayList<String> iFragmentList = null;

	SendSMS ()
	{
		iSMSManager = SMSManager.getDefault ();
	}

	public boolean sendSMSMessage (String aDestination, String aMessageText)
	{
		if (iSMSManager == null)
                  {
			return (false);
                  }
		
                  int fragmentCount = 0;
		
		iFragmentList = iSMSManager.divideMessage (aMessageText);
		fragmentCount = iFragmentList.Count ();
		if (fragmentCount > 1)
		{
			iSMSManager.SendMultipartMessage (aDestinationAddress, null, iFragmentList, null, null, null);
		}
		else
		{
			iSMSManager.SendTextMessage (aDestinationAddress, null, aMessageText, null, null, null);
		}
		
		return true;	
	}
}

// end of file

See Also

Download

The source code for this project is in the Android Cookbook repository, http://github.com/IanDarwin/Android-Cookbook-Examples/tree/master/SendSMS