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 Messages

Author: Colin Wilcox
Published? true -- FormatLanguage: W

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

Download:

The source code for this project is in the Android Cookbook repository at http://github.com/IanDarwin/Android-Cookbook-Examples, in the subdirectory SendSMS.
No records found.