5,386
社区成员
发帖
与我相关
我的任务
分享
uses
FMX.PhoneDialer;
type
TFormPhoneMain=class(TForm)
constructor Create(AOwner: TComponent); override;
procedure MyOnCallStateChanged(const ACallID: String; const ACallState: TCallState);
private
PhoneDialerService: IFMXPhoneDialerService;
{Form}
constructor TFormPhoneMain.Create(AOwner: TComponent);
begin
inherited 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: String;
MyNotification: TNotification;
Begin
case ACallState of
TCallState.None:
outText:='无通话';
TCallState.Connected:
outText:='接通';
TCallState.Incoming:
outText:='来电';
TCallState.Dialing:
outText:='去电';
TCallState.Disconnected:
outText:='挂断';
end;
s:='';
with UniQuery6 do
begin
Close;
ParamByName('V').Value:=ACallID;
Open;
if RecordCount>0 then
s:=FieldByName('User_Name').AsString+' '+outText
else
s:='未知号码 '+outText;
end;
lblCallState.Text:='当前通话状态 '+s+': '+ACallID;
FormActivate(nil);
if (outText='来电')or(outText='去电') then
begin
Timer1.Enabled:=True;
// Create an instance of TNotification
MyNotification:=NotificationCenter1.CreateNotification;
try
MyNotification.Name:='来电显示';
// --- 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 the Icon Badge Number to be displayed.
NotificationCenter1.PresentNotification(MyNotification);
finally
MyNotification.DisposeOf;
end;
end
else
begin
Timer1.Enabled:=False;
NotificationCenter1.CancelNotification('来电显示');
BringAppToFront(TJIntent.JavaClass.ACTION_MAIN);
end;
End;
[JavaSignature('android/telephony/PhoneStateListener')]
JPhoneStateListener = interface(JObject)
['{50CE10E1-C584-4145-BC72-65BFA48BB281}']
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; overload;
procedure onDataConnectionStateChanged(state: Integer; networkType: Integer); cdecl; overload;
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<JPhoneStateListenerClass, JPhoneStateListener>) end;