Home > Back-end >  Delphi xe android to monitor calls to some models, listening is less than to seek a solution
Delphi xe android to monitor calls to some models, listening is less than to seek a solution

Time:09-17

According to Delphi xe help document
 
USES the
FMX. PhoneDialer;
Type
TFormPhoneMain=class (TForm)
The constructor Create (AOwner: TComponent); Override.
Procedure MyOnCallStateChanged (const ACallID: String; Const ACallState: TCallState);
Private
PhoneDialerService: IFMXPhoneDialerService;

{Form}
The constructor TFormPhoneMain. Create (AOwner: TComponent);
The begin
Inherited the Create (AOwner);
TPlatformServices. Current. SupportsPlatformService (IFMXPhoneDialerService, IInterface (PhoneDialerService));
If Assigned (PhoneDialerService) then
PhoneDialerService. OnCallStateChanged:=MyOnCallStateChanged;
end;

Procedure TFormPhoneMain. MyOnCallStateChanged (const ACallID: String; Const ACallState: TCallState);
Var
OutText, s: a String;
MyNotification: TNotification;
The Begin
Case ACallState of
TCallState. None:
OutText:='no talk;
TCallState. Connected:
OutText:='connected';
TCallState. Incoming:
OutText:='call';
TCallState. Dialing:
OutText:='to';
TCallState. Disconnected:
OutText:='hang up;
end;
S:=';
With UniQuery6 do
The begin
The Close;
ParamByName (' V '). The Value:=ACallID;
The Open;
If RecordCount> 0 then
S:=FieldByName (" User_Name "). The AsString + "+ outText
The else
S:='unknown number + outText;
end;
LblCallState. Text:='current state calls' + s + + ACallID' : ';
FormActivate (nil);
If (outText='call') or (outText='to') then
The begin
Timer1. Enabled:=True;
//Create an instance of TNotification
MyNotification:=NotificationCenter1. CreateNotification;
Try
MyNotification. Name:='caller id;
//-- - your code goes here -- -- --
//Set the icon or notification number
MyNotification. Number:=18;
//Set the alert message
MyNotification. AlertBody:=lblCallState. Text;
//Note: You must send the notification to the notification center for Icon Badge Number to be displayed.
NotificationCenter1. PresentNotification (MyNotification);
The finally
MyNotification. DisposeOf;
end;
End
The else
The begin
Timer1. Enabled:=False;
NotificationCenter1. CancelNotification (" caller id ");
BringAppToFront (TJIntent JavaClass. ACTION_MAIN);
end;
The End;


Results on some phones can come normal access to electricity, and the call number and self-built telephone this match, the caller information notice; And most of the new mobile phone can't listening; Online query a circle, there are such things happen, JAVA used to create a new listening to solve, but Delphi xe current information is too little, didn't find a solution for a long time, someone has a solution or suggestion?

Refer to some related JAVA code on the net, feeling through self-built listening, probably can solve, analyzes Androidapi. JNI. Telephony unit, found TJPhoneStateListener class should be able to achieve the demand of them, it is defined as such:
 [JavaSignature (' android/Telephony/PhoneStateListener)] 
JPhoneStateListener=interface (JObject)
[' {ce10e1 - C584 50-4145 - BC72-65 bfa48bb281} ']
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); Cdecl; The phrase ";
Procedure onDataConnectionStateChanged (state: Integer; NetworkType: Integer); Cdecl; The phrase ";
Procedure onMessageWaitingIndicatorChanged (mwi: Boolean); Cdecl;
Procedure onServiceStateChanged (serviceState: JServiceState); Cdecl;
Procedure onSignalStrengthChanged (asu: Integer); Cdecl;//Deprecated
Procedure onSignalStrengthsChanged (signalStrength: JSignalStrength); Cdecl;
end;
TJPhoneStateListener=class (TJavaGenericImport) end;

Here's the thing, how should I use?

CodePudding user response:

Should be the problem of rights management, see: https://newsgroups.embarcadero.com/thread.jspa? ThreadID=245771

CodePudding user response:

Delphi xe material too little at present

CodePudding user response:

reference 1st floor DelphiGuy response:
should be the problem of rights management, see: https://newsgroups.embarcadero.com/thread.jspa? ThreadID=245771

Thank you, I try this post gives solution, doubt android version 6.0 permissions to less than, you need to explicitly give permission; In addition, is that the SDK version is too low, to upgrade the v4 file

CodePudding user response:

USES the
Androidapi. Helpers, Androidapi JNIBridge, Androidapi. JNI. JavaTypes;

.

Var
LPermissions: TJavaObjectArray;
The begin
LPermissions:=TJavaObjectArray The Create (1);
LPermissions. Items [0] :=StringToJString (' android. Permission. READ_PHONE_STATE ');
TAndroidHelper. Activity. RequestPermissions (LPermissions, 0);
end;


The question now is, because the Activity of Delphi realize onRequestPermissionsResult, so you don't know
Whether the user really given permission; At least, not by the method of the asynchronous solution to this problem is likely to be
At some point later check permissions, the problem is
No import in Delphi RTL appropriate Java classes (PermissionChecker), I just happened to do the import, and create the
The code below:

Type
TAndroidPermissions=class (TObject)
Public
='android. Permission. Const CAMERA CAMERA';
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related