CarioJr
Members-
Content Count
9 -
Joined
-
Last visited
Community Reputation
2 Neutral-
Using you sample in delphi i can get the number, status, and duration off the call.
-
I didin't try. For me only matter the number, my client wants to know who is calling and the relationated data in my software during the call. Now I finaly get the number! But unfortunately not on delphi!
-
I tried in android studio, it works in versions below 9. But my client have a galaxy s30 with the android 10. In him The number came null, in my manifest i think i put all the permissions. Can you help me? <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> <uses-permission android:name="android.permission.READ_CALL_LOG"/>
-
Do you set the function on a timer, where do you call her? I can read the log but, it is comming with all call logs, Can i bring just the last ones?
-
Can you give me an exemple?
-
I tried in a device with android 4.4 and it works. But is very obsolet.
-
To me, never works. What android version are you using to test? Thanks.
-
Hi, and Thanks for your help! I modified my code to seems more like yours, and stil not working. My callstatechanged not trigger. Am i missing something? unit Principal; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.Permissions, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.PhoneDialer, FMX.Platform, FMX.Edit, FMX.ListBox, FMX.Layouts, FMX.Controls.Presentation; type TFrmPrincipal = class(TForm) Layout2: TLayout; Label1: TLabel; edtPhoneNumber: TEdit; btnCall: TButton; Timer1: TTimer; lblCallState: TLabel; // procedure FormCreate(Sender: TObject); procedure btnCallClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } FPhoneDialerService: IFMXPhoneDialerService; FCallPhonePermission: string; procedure DisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc); procedure MakePhoneCallPermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>); procedure MyOnCallStateChanged(const ACallID: String; const ACallState: TCallState); public end; var FrmPrincipal: TFrmPrincipal; implementation {$R *.fmx} {$R *.LgXhdpiTb.fmx ANDROID} {$R *.LgXhdpiPh.fmx ANDROID} uses {$IFDEF ANDROID} Androidapi.Helpers, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os, {$ENDIF} FMX.DialogService; procedure TFrmPrincipal.btnCallClick(Sender: TObject); begin { test whether the PhoneDialer services are supported } if FPhoneDialerService <> nil then begin { if the Telephone Number is entered in the edit box then make the call, else display an error message } if edtPhoneNumber.Text <> '' then PermissionsService.RequestPermissions([FCallPhonePermission], MakePhoneCallPermissionRequestResult, DisplayRationale) else begin ShowMessage('Please type in a telephone number.'); edtPhoneNumber.SetFocus; end; end else ShowMessage('PhoneDialer service not supported'); end; procedure TFrmPrincipal.DisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc); begin // Show an explanation to the user *asynchronously* - don't block this thread waiting for the user's response! // After the user sees the explanation, invoke the post-rationale routine to request the permissions ShowMessage('The app needs to be able to support your making phone calls'); // procedure(const AResult: TModalResult) // begin // APostRationaleProc; // end) end; procedure TFrmPrincipal.FormCreate(Sender: TObject); const PermissionAccessReadPhoneState = 'android.permission.READ_PHONE_STATE'; PermissionAccessMakeCall = 'android.permission.CALL_PHONE'; PermissionAccessReadCallLog = 'android.permission.READ_CALL_LOG'; begin FCallPhonePermission := PermissionAccessMakeCall; TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, IInterface(FPhoneDialerService)); PermissionsService.RequestPermissions([PermissionAccessMakeCall, PermissionAccessReadPhoneState, PermissionAccessReadCallLog], procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>) begin if (Length(AGrantResults) = 3) and (AGrantResults[0] = TPermissionStatus.Granted) and (AGrantResults[1] = TPermissionStatus.Granted) then begin ShowMessage('READ_PHONE_STATE + CALL_PHONE Activated + call_log!'); end; end); if Assigned(FPhoneDialerService) then begin FPhoneDialerService.OnCallStateChanged := MyOnCallStateChanged; end; end; procedure TFrmPrincipal.MakePhoneCallPermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>); begin if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then FPhoneDialerService.Call(edtPhoneNumber.Text) else ShowMessage('Cannot make a phone call because the required permission has not been granted'); end; procedure TFrmPrincipal.MyOnCallStateChanged(const ACallID: String; const ACallState: TCallState); var outText: String; begin case ACallState of TCallState.None: outText := 'No calls'; TCallState.Connected: outText := 'Connected'; TCallState.Incoming: outText := 'Incoming Call'; TCallState.Dialing: outText := 'Dialing'; TCallState.Disconnected: outText := 'Disconnected'; end; lblCallState.Text := outText; end; end.
-
Hello, I put the example to test, it doesn't work. It seems to me that this event, CallStateChanged is not working. I already test in diferent android versions, and doesn't work. This is my code. Am i doing something whorng? For make calls it works. unit Principal; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.Permissions, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.PhoneDialer, FMX.Platform, FMX.Edit, FMX.ListBox, FMX.Layouts, FMX.Controls.Presentation; type TFrmPrincipal = class(TForm) Layout2: TLayout; Label1: TLabel; edtPhoneNumber: TEdit; btnCall: TButton; lbInfo: TListBox; lbCalls: TListBox; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure btnCallClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } FPhoneDialerService: IFMXPhoneDialerService; FCallPhonePermission: string; procedure DisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc); procedure MakePhoneCallPermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>); procedure CallStateChanged(const ACallID: string; const AState: TCallState); function CallStateAsString(AState: TCallState): String; public end; var FrmPrincipal: TFrmPrincipal; implementation {$R *.fmx} {$R *.LgXhdpiTb.fmx ANDROID} {$R *.LgXhdpiPh.fmx ANDROID} uses {$IFDEF ANDROID} Androidapi.Helpers, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os, {$ENDIF} FMX.DialogService; procedure TFrmPrincipal.btnCallClick(Sender: TObject); begin { test whether the PhoneDialer services are supported } if FPhoneDialerService <> nil then begin { if the Telephone Number is entered in the edit box then make the call, else display an error message } if edtPhoneNumber.Text <> '' then PermissionsService.RequestPermissions([FCallPhonePermission], MakePhoneCallPermissionRequestResult, DisplayRationale) else begin ShowMessage('Please type in a telephone number.'); edtPhoneNumber.SetFocus; end; end else ShowMessage('PhoneDialer service not supported'); end; function TFrmPrincipal.CallStateAsString(AState: TCallState): String; begin case AState of TCallState.None: Result := 'None'; TCallState.Connected: Result := 'Connected'; TCallState.Incoming: Result := 'Incoming'; TCallState.Dialing: Result := 'Dialing'; TCallState.Disconnected: Result := 'Disconnected'; else Result := '<unknown>'; end; end; procedure TFrmPrincipal.CallStateChanged(const ACallID: string; const AState: TCallState); var Calls: TCalls; Call: TCall; begin if AState = TCallState.Incoming then begin Calls := FPhoneDialerService.GetCurrentCalls; try for Call in Calls do begin if Call.GetCallID = ACallID then begin ShowMessage(ACallID); Exit; end; end; finally for Call in Calls do Call.Free; end; end; end; procedure TFrmPrincipal.DisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc); begin // Show an explanation to the user *asynchronously* - don't block this thread waiting for the user's response! // After the user sees the explanation, invoke the post-rationale routine to request the permissions ShowMessage('The app needs to be able to support your making phone calls'); // procedure(const AResult: TModalResult) // begin // APostRationaleProc; // end) end; procedure TFrmPrincipal.FormCreate(Sender: TObject); begin {$IFDEF ANDROID} FCallPhonePermission := JStringToString(TJManifest_permission.JavaClass.CALL_PHONE); {$ENDIF} { test whether the PhoneDialer services are supported } TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, FPhoneDialerService); lbInfo.clear; if TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, IInterface(FPhoneDialerService)) then begin FPhoneDialerService.OnCallStateChanged := CallStateChanged; lbInfo.ItemHeight := lbInfo.ClientHeight / 4; lbInfo.Items.Add('Carrier Name: ' + FPhoneDialerService.GetCarrier.GetCarrierName); lbInfo.Items.Add('ISO Country Code: ' + FPhoneDialerService.GetCarrier.GetIsoCountryCode); lbInfo.Items.Add('Network Code: ' + FPhoneDialerService.GetCarrier.GetMobileCountryCode); lbInfo.Items.Add('Mobile Network: ' + FPhoneDialerService.GetCarrier.GetMobileNetwork); // lbInfo.Items.Add('Status: ' + btnCall.Enabled := True; end else lbInfo.Items.Add('No Phone Dialer Service'); if TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, FPhoneDialerService) then FPhoneDialerService.OnCallStateChanged := CallStateChanged; end; procedure TFrmPrincipal.MakePhoneCallPermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>); begin // 1 permission involved: CALL_PHONE if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then FPhoneDialerService.Call(edtPhoneNumber.Text) else ShowMessage('Cannot make a phone call because the required permission has not been granted'); end; procedure TFrmPrincipal.Timer1Timer(Sender: TObject); begin end; end.