Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send SMS with Delphi XE5 in Android

Does anybody know how to get this to work? The closest I got was the code below, but got no success. At first, it gives you some hope when it tells you need the SEND_SMS permission. But after you setup this permission, nothing happens!

uses
 Androidapi.JNI.JavaTypes;

procedure TForm1.Button1Click(Sender: TObject);
var
  smsManager: JSmsManager;
  smsTo, smsFrom: JString;
begin
  smsManager:= TJSmsManager.JavaClass.getDefault;
  smsTo:= StringToJString('552199999999'); //replace with the right destination number
  smsFrom:= StringToJString('552499999999'); //replace with the right originator number
  smsManager.sendTextMessage(smsTo, smsFrom, StringToJString(Edit1.Text), nil, nil);
end;
like image 608
rribas Avatar asked Sep 17 '13 02:09

rribas


People also ask

How to send sms from Delphi?

How to send sms from Delphi. The most simple way to send SMS from Delphi is to use the built in HTTP/Rest SMS api of Ozeki SMS Gateway. When you use this API, you will send SMS messages by issuing a HTTP Post request to the SMS gateway. The HTTP Post request will contain a message formatted in json format.

Can Tasker send SMS?

What's a Tasker profile? A Tasker action is something that you want your phone to do: send a text message, change an audio level, turn Bluetooth on and so on.


2 Answers

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;
like image 71
mh taqia Avatar answered Sep 22 '22 13:09

mh taqia


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);
like image 27
Deltics Avatar answered Sep 22 '22 13:09

Deltics