Murat Kerimoglu
asked on
How can I receive SMS?
Dear My Friends, Hello,
How can I receive SMS ?
I'm using this code:
But there isn't any result for TMemo.
There isn't any error in my code but
JTelephonySmsIntentsClass( IJavaClass ) - error
JTelephonySmsIntents(IJava Instance) - error
TJTelephonySmsIntents = class(TJavaGenericImport<J TelephonyS msIntentsC lass, JTelephonySmsIntents>) - ok
in Structure Window
I'm using Delphi 10.2 Tokyo - Android Platform.
Thanks, Greetings.
How can I receive SMS ?
I'm using this code:
uses
Androidapi.JNI.JavaTypes,
Androidapi.JNI.Telephony,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.Helpers;
...
type
JTelephonySmsIntentsClass = interface(IJavaClass)
['{73FFA042-DAE3-497F-B9D4-B7F1B178E941}']
{class} function getMessagesFromIntent(intent: JIntent): TJavaArray<JSmsMessage>; cdecl;
{class} function _GetSMS_RECEIVED_ACTION: JString; cdecl;
{class} property SMS_RECEIVED_ACTION: JString read _GetSMS_RECEIVED_ACTION; end;
[JavaSignature('android/provider/Telephony/Sms/Intents')]
JTelephonySmsIntents = interface(IJavaInstance)
['{42798E28-0E3A-4287-8EE9-606BB9D311B5}'] end;
TJTelephonySmsIntents = class(TJavaGenericImport<JTelephonySmsIntentsClass, JTelephonySmsIntents>) end;
...
procedure TForm1.BroadcastReceiverReceive(Context: JContext; Intent: JIntent);
var
i: Integer;
msgs: TJavaArray<JSmsMessage>;
msg : JSmsMessage;
phonenumber, body : string;
begin
if Intent.getAction.compareTo(TJTelephonySmsIntents.JavaClass.SMS_RECEIVED_ACTION) = 0 then
begin
msgs := TJTelephonySmsIntents.JavaClass.getMessagesFromIntent(Intent);
for i := 0 to msgs.Length - 1 do
begin
msg := msgs[i];
phonenumber := JStringToString(msg.getOriginatingAddress);
body := JStringToString(msg.getDisplayMessageBody);
Memo1.Lines.Add(phonenumber + ' : ' + body);
end;
end;
end;
But there isn't any result for TMemo.
There isn't any error in my code but
JTelephonySmsIntentsClass(
JTelephonySmsIntents(IJava
TJTelephonySmsIntents = class(TJavaGenericImport<J
in Structure Window
I'm using Delphi 10.2 Tokyo - Android Platform.
Thanks, Greetings.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.