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=245771CodePudding user response:
Delphi xe material too little at presentCodePudding user response: