How to send SMS with Delphi XE5 in Android How to send SMS with Delphi XE5 in Android android android

How to send SMS with Delphi XE5 in Android


Try to pass empty value (nil) to the scAddress parameter of the sendTextMessage function call to use the current default SMS center:

uses  Androidapi.JNI.JavaTypes, Androidapi.JNI.Telephony;procedure TForm1.Button1Click(Sender: TObject);var  smsTo: JString;  smsManager: JSmsManager;begin  smsManager := TJSmsManager.JavaClass.getDefault;  smsTo := StringToJString('091...');  smsManager.sendTextMessage(smsTo, nil, StringToJString('Test SMS'), nil, nil);end;


The second parameter to sendTextMessage is not the "sender" number, rather it identifies the SMS provider service center.

You almost certainly did not want to specify anything here. Simply pass nil and the SMSManager will use the device default service center for delivering your message.

sRecipient := StringToJString(edRecipient.Text);sMessage   := StringToJString(edMessage.Text);sendTextMessage(sRecipient, nil, sMessage, nil, nil);


See also:

http://delphi-android.blogspot.dk/2013/10/how-to-send-sms-with-delphi-on-android.html

for a copy & paste function.

I like to have such functions in a separate unit, instead of putting it into the Button's event handler.