Problem on PhoneStateListener to listen to OnCellInfoChanged in delphi firemonkey

  

It will be appreciated if help me. i am writing a program with delphi firemonkey that show mobile cell informations. i need to listen on cell info changes with JPhoneStateListener class.
At First i write a class for implement main class as below :

type
TPL = class(TJavaGenericImport<JPhoneStateListenerClass, JPhoneStateListener>)
public
constructor create;
Destructor Destroy; Override;
procedure onCallForwardingIndicatorChanged(cfi: Boolean); cdecl;
procedure onCallStateChanged(state: Integer; incomingNumber: JString); cdecl;
……… (and other procedures of main class)
end;
Implementation

Constructor TPL.Create;
Begin

End;
Destructor TPL.Destroy;
Begin
Inherited Destroy;
End;
procedure TPL.onCallForwardingIndicatorChanged(cfi: Boolean);
Begin

End;
………

and in main code :

procedure TForm1.Button1Click(Sender: TObject);
var
obj: JObject;
TelephonyManager: JTelephonyManager;
Tj:TPL;
begin
obj := TAndroidHelper.Context.getSystemService(TJContext.JavaClass.TELEPHONY_SERVICE);
if (obj<>nil) then
begin
TelephonyManager := TJTelephonyManager.Wrap((obj as ILocalObject).GetObjectID);
if (TelephonyManager<>nil) then
begin
Tj := TPL.create;
TelephonyManager.listen(Tj, TJPhoneStateListener.JavaClass.LISTEN_CELL_INFO or TJPhoneStateListener.JavaClass.LISTEN_CELL_LOCATION); <—— Error is here
end;
end;
end;

at compile i face with this error:

[DCC Error] main.pas(61): E2010 Incompatible types: ‘JPhoneStateListener’ and ‘TPL’

thanks to @nolaspeaker

i edit my code as below :

unit main;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, FMX.ExtCtrls, FMX.Helpers.Android, RTL.Controls,
Androidapi.JNI.Os, Androidapi.Helpers, Androidapi.JNI.Telephony,
Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.JavaTypes,
Androidapi.JNIBridge, Androidapi.JNI.App;

type
TPhoneStateListener = class;

TForm1 = class(TForm)
Button1: TButton;
RTLFixer1: TRTLFixer;
Memo1: TMemo;
Timer1: TTimer;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure InitPSListener(Start: Boolean);
private
PhoneStateListener: TPhoneStateListener;
FSignal: Integer;
{ Private declarations }
public
{ Public declarations }
end;

//type
TPhoneStateListener = class(TJavaLocal, JICustomPhoneStateListener)
private
[weak]
FParent : TForm1;
public
constructor Create(AParent : TForm1);
procedure onCallForwardingIndicatorChanged(cfi: Boolean); cdecl;
procedure onCallStateChanged(state: Integer; incomingNumber: JString); cdecl;
procedure onCellInfoChanged(cellInfo: JList); cdecl;
procedure onCellLocationChanged(location: JCellLocation); cdecl;
procedure onDataActivity(direction: Integer); cdecl;
procedure onDataConnectionStateChanged(state: Integer); overload; cdecl;
procedure onDataConnectionStateChanged(state: Integer; networkType: Integer); overload; cdecl;
procedure onMessageWaitingIndicatorChanged(mwi: Boolean); cdecl;
procedure onServiceStateChanged(serviceState: JServiceState); cdecl;
procedure onSignalStrengthChanged(asu: Integer); cdecl;
procedure onSignalStrengthsChanged(signalStrength: JSignalStrength); cdecl;
end;

var
Form1: TForm1;

implementation
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID}

{$R *.LgXhdpiPh.fmx ANDROID}

procedure TForm1.Button1Click(Sender: TObject);
begin
InitPSListener(True);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
InitPSListener(False);
end;

procedure TForm1.InitPSListener(Start: Boolean);
var
obj: JObject;
begin

if PhoneStateListener = nil then
PhoneStateListener := TPhoneStateListener.Create(Self);
obj := TAndroidHelper.Context.getSystemService(TJContext.JavaClass.TELEPHONY_SERVICE);
if obj <> nil then
begin
CallinUIThread(procedure
var
TelephonyManager: JTelephonyManager;
PSL: JCustomPhoneStateListener;
begin
TelephonyManager := TJTelephonyManager.Wrap(obj);
PSL := TJCustomPhoneStateListener.JavaClass.init(PhoneStateListener);
if Start then
TelephonyManager.listen(PSL,
TJPhoneStateListener.JavaClass.LISTEN_SIGNAL_STRENGTHS)
// or TJPhoneStateListener.JavaClass.LISTEN_SIGNAL_STRENGTH
// or TJPhoneStateListener.JavaClass.LISTEN_DATA_ACTIVITY
else
TelephonyManager.listen(PSL,
TJPhoneStateListener.JavaClass.LISTEN_NONE)
end
);
end;

end;

{ TPhoneStateListener }

constructor TPhoneStateListener.Create(AParent: TForm1);
begin
inherited Create;
FParent := AParent;
end;

procedure TPhoneStateListener.onCallForwardingIndicatorChanged(cfi: Boolean);
begin
end;

procedure TPhoneStateListener.onCallStateChanged(state: Integer;
incomingNumber: JString);
begin
end;

procedure TPhoneStateListener.onCellInfoChanged(cellInfo: JList);
begin
end;

procedure TPhoneStateListener.onCellLocationChanged(location: JCellLocation);
begin
end;

procedure TPhoneStateListener.onDataActivity(direction: Integer);
begin
end;

procedure TPhoneStateListener.onDataConnectionStateChanged(state: Integer);
begin
end;

procedure TPhoneStateListener.onDataConnectionStateChanged(state,
networkType: Integer);
begin
end;

procedure TPhoneStateListener.onMessageWaitingIndicatorChanged(mwi: Boolean);
begin
end;

procedure TPhoneStateListener.onServiceStateChanged(
serviceState: JServiceState);
begin
end;

procedure TPhoneStateListener.onSignalStrengthChanged(asu: Integer);
begin
end;

procedure TPhoneStateListener.onSignalStrengthsChanged(
signalStrength: JSignalStrength);
begin
FParent.onSignalStrengthsChanged(signalStrength); <—- error is here
end;

procedure TForm1.OnSignalStrengthsChanged(signalStrength: JSignalStrength);
begin
FSignal := signalStrength.getLevel; // 0 – 4 <—– and is here
end;

end.

but still ai have error :
[DCC Error] main.pas(249): E2003 Undeclared identifier: ‘onSignalStrengthsChanged’

Comments are closed.