0

I need to get information about outgoing and incoming calls on an Android phone using Delphi 10.3 Rio.

There's many info I want to get about the calls (it's duration, the number of the other phone, if the call was made from this phone or received, etc.), but for now I'm starting with the (I think) most basic information I can get and check for the call state (dialing, connected, disconnected and so on).

I know there's a function for that in Delphi but I haven't been able to make it work. I've been following Delphi's tutorial on how to use the IFMXPhoneDialerService to do so, but it doesn't seem to work. I reassigned IFMXPhoneDialerService's OnCallStateChanged event to a custom one but the custom one is never reached.

Here's how I've been doing it

interface

uses
  FMX.Controls,
  FMX.Controls.Presentation,
  FMX.Dialogs,
  FMX.Edit,
  FMX.Forms,
  FMX.PhoneDialer,
  FMX.Platform,
  FMX.StdCtrls,
  FMX.Types,
  System.Classes;

type
  TQReportsDialerForm = class(TForm)
  private
    PhoneDialerService: IFMXPhoneDialerService;
    procedure MyOnCallStateChanged(const ACallID: String;
      const ACallState: TCallState);
  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  QReportsDialerForm: TQReportsDialerForm;

implementation

{$R *.fmx}
{$R *.XLgXhdpiTb.fmx ANDROID}
{$R *.LgXhdpiPh.fmx ANDROID}

procedure TQReportsDialerForm.MyOnCallStateChanged(const ACallID: string;
  const ACallState: TCallState);
var
  outText: string;
begin
  Log.d('Entered custom call state handler');
  case ACallState of
    TCallState.Connected:
      outText := 'Connected';
    TCallState.Dialing:
      outText := 'Dialing';
    TCallState.Disconnected:
      outText := 'Disconnected';
    TCallState.Incoming:
      outText := 'Incoming';
    TCallState.None:
      outText := 'No calls';
  end;
  lblCallState.Text := outText;
end;

constructor TQReportsDialerForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService,
    IInterface(PhoneDialerService));
  if Assigned(PhoneDialerService) then
  begin
    PhoneDialerService.OnCallStateChanged := MyOnCallStateChanged;
    Log.d('PhoneDialerService correctly assigned.');
  end
  else
    Log.d('Couldn''t assign PhoneDialerService.');
end;

end.

I know the dialer service is assigned because the code logs the PhoneDialerService correctly assigned. message, but when a call state changes it doesn't log the Entered custom call state handler message on MyOnCallStateChanged procedure.

As an additional info, something I found rather strange is that when I'm debugging the app, if I look at the type of OnCallStateChanged after assigning it, it shows as an "Erroneous type", so I think I may be doing something wrong there, but I haven't been able to see where the error is.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Roäc
  • 149
  • 19

0 Answers0