Sunday, October 27, 2013

How to send SMS with Delphi on Android

Remember to go into Project/Options/Permissions and allow the app to send SMS. The code is:

uses
  FMX.Helpers.Android,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Net,
  Androidapi.JNI.JavaTypes,
  Androidapi.JNI.Telephony;

procedure SendSMS (target,messagestr:string);
var
  smsManager: JSmsManager;
  smsTo: JString;
begin
  smsManager:= TJSmsManager.JavaClass.getDefault;
  smsTo:= StringToJString(target);
  smsManager.sendTextMessage(smsTo, nil, StringToJString(messagestr), nil, nil);
end;

17 comments:

  1. is it possible to access the contact directory of android with XE5?

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. how can validate a php form with a android XE5 app ?

    ReplyDelete
  4. I HAVE PROBLEM WITH THIS CODE MY DELPHI XE10 DASE NOT RECONIZ STRINGTOJSTRING

    ReplyDelete
    Replies
    1. Make sure you put Androidapi.Helpers in the uses section.

      Delete
    2. Make sure you have Androidapi.Helpers in the uses section.

      Delete
    3. Make sure you have Androidapi.Helpers in the uses section.

      Delete
    4. Make sure you put Androidapi.Helpers in the uses section.

      Delete
    5. Make sure you put Androidapi.Helpers in the uses section.

      Delete
  5. لاه ذا لاه عذبتونا هجاوبو

    ReplyDelete
  6. راهم جاوبك
    "
    ajoutez Androidapi.Helpers à la place FMX.Helpers.Android, in the uses section.

    ReplyDelete
  7. how can choose the sim card send over .

    ReplyDelete
  8. Merci pour les codes, malheureusement ça envoi seulement les messages court! comment envoyer un message long?

    ReplyDelete
  9. Comment envoyer un message long?

    ReplyDelete
  10. comment envoyer un sms sans qu'il affiche dans l'application par défaut du téléphone?

    ReplyDelete
  11. how to know that the sms has been sent?
    confirmation

    ReplyDelete