Jump to content
Sign in to follow this  
Arsl01

Delphi FMX SMS Receiver Unable to Retrieve PDU Content

Recommended Posts

procedure TForm1.AndroidBroadcastReceiver2Receive(csContext: JContext; csIntent: JIntent);
var
  Bundle: JBundle;
  PDUs: TJavaObjectArray<JObject>;
  Sms: JSmsMessage;
  Sender, MessageBody: string;
  I: Integer;
  PDU: TJavaArray<Byte>;
begin
  try
    memo1.Lines.Add('SMS received.');

    // Intent kontrolü
    if not csIntent.getAction.equals(StringToJString('android.provider.Telephony.SMS_RECEIVED')) then
    begin
      memo1.Lines.Add('This intent is not SMS_RECEIVED.');
      Exit;
    end;

    // Bundle al
    Bundle := csIntent.getExtras;
    if Bundle = nil then
    begin
      memo1.Lines.Add('Bundle is empty.');
      Exit;
    end;

    // pdus anahtarını kontrol et
    if not Bundle.containsKey(StringToJString('pdus')) then
    begin
      memo1.Lines.Add('pdus key not found.');
      Exit;
    end;

    // pdus değerini al
    PDUs := Bundle.get(StringToJString('pdus')) as TJavaObjectArray<JObject>;
    if PDUs = nil then
    begin
      memo1.Lines.Add('Failed to convert PDUs.');
      Exit;
    end;

    memo1.Lines.Add('PDUs successfully retrieved.');

    // PDUs içindeki her bir PDU'yu işle
    for I := 0 to PDUs.Length - 1 do
    begin
      // Her bir PDU öğesini byte array'e dönüştür
      PDU := TJavaArray<Byte>.Wrap((PDUs.Items[I] as ILocalObject).GetObjectID);

      // PDU'yu SmsMessage'e dönüştür
      Sms := TJSmsMessage.JavaClass.createFromPdu(PDU);

      // Gönderen ve mesaj içeriğini al
      Sender := JStringToString(Sms.getDisplayOriginatingAddress);
      MessageBody := JStringToString(Sms.getMessageBody);

      // Gönderen ve mesajı logla
      memo1.Lines.Add('Sender: ' + Sender);
      memo1.Lines.Add('Message: ' + MessageBody);
    end;

  except
    on E: Exception do
      memo1.Lines.Add('General error: ' + E.Message);
  end;
end;

Hello everyone,

I'm working on an SMS receiver application using Delphi FMX. I can successfully create the receiver and access the PDU key, but the PDU content is not coming through, and as a result, I am unable to read the SMS content.

The app is set as the default SMS application. However, I've spent a lot of time on this issue and still can't find a solution. Has anyone encountered a similar issue or have any suggestions on how to resolve this?

Thank you in advance for your help.

 

 

Share this post


Link to post

PDUs := Bundle.get(StringToJString('pdus')) as TJavaObjectArray<JObject>;

PDU value does not appear in this line

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×