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;
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With