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

In Chapter: Telephone Applications
Author: Colin Wilcox ('NavaronUK')
Published? true
FormatLanguage: WikiFormat


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


Use the SMSManager.


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);
			iSMSManager.SendTextMessage (aDestinationAddress, null, aMessageText, null, null, null);
		return true;	

// end of file


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


If you found this recipe useful, why not buy the book and have the whole collection always at hand?"