c2design 10월 28일, 2022에 포스트됨 공유하기 10월 28일, 2022에 포스트됨 본 게시글의 내용은 안드로이드 및 Rad Studio 버전 업데이트에 따른 환경 변화에 따라 정상 실행이 안될 수도 있습니다. 게시글를 작성하는 싯점 (2022.10.28) 에서의 프로젝트 환경은 다음과 같습니다. 프로젝트 환경 : 안드로이드 12 버전 / Rad Studio Delphi 11.2 Patch 1 안드로이드 12 에서 전화걸기 오류로 아래 퀄리티포털에 등록된 내용을 참고하여 보완 하였습니다. https://quality.embarcadero.com/browse/RSP-39445 사용된 샘플은 아래 게시글의 퍼미션 등록 관련된 소스에 전화걸기 기능을 추가 하여 업그레이드 하였습니다. 1. c:\Program Files (x86)\Embarcadero\Studio\22.0\source\fmx\FMX.PhoneDialer.Android.pas 파일을 전화걸기 샘플 프로젝트의 소스가 위치한 폴더에 복사합니다. 복사만 하고 샘플 프로젝트에 포함 시키지는 않습니다. 2. FMX.PhoneDialer.Android.pas 파일의 읽기 전용 속성을 제거 합니다. 3. 아래와 같이 수정 합니다. procedure RegisterPhoneDialerService; begin if PermissionsService.IsPermissionGranted(JStringToString(TJManifest_permission.JavaClass.READ_PHONE_STATE)) then // 추가된 부분 begin if TAndroidHelper.HasSystemService(TJPackageManager.JavaClass.FEATURE_TELEPHONY) then TPlatformServices.Current.AddPlatformService(IFMXPhoneDialerService, TAndroidPhoneDialerService.Create); end; end; 4. 프로젝트 옵션에서 퍼미션 항목을 체크 합니다. ( CALL_PHONE, Continu_A_Call~, READ_Phone_State ) 5. 실행 소스 unit PMUnit; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.Permissions, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, FMX.DialogService, FMX.Platform, FMX.PhoneDialer; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; BT_Call: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure BT_CallClick(Sender: TObject); private FPhoneDialerService: IFMXPhoneDialerService; // 전화걸기 서비스 용 procedure DisplayRationale(Sender: TObject; const APermissions: TClassicStringDynArray; const APostRationaleProc: TProc); procedure Loacation_PermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray); procedure Call_PermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray); procedure Camera_PermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray); { Private declarations } public { Public declarations } FPermissionLoacation, FPermissionCall, FPermissionCamera : string; end; var Form1: TForm1; implementation uses {$IFDEF ANDROID} Androidapi.JNI.Os, Androidapi.Helpers, AndroidApi.Jni.JavaTypes; {$ENDIF} {$R *.fmx} procedure TForm1.FormCreate(Sender: TObject); begin FPermissionLoacation := JStringToString(TJManifest_permission.JavaClass.ACCESS_FINE_LOCATION ); FPermissionCall := JStringToString(TJManifest_permission.JavaClass.CALL_PHONE ); FPermissionCamera := JStringToString(TJManifest_permission.JavaClass.CAMERA ); TPlatformServices.Current.SupportsPlatformService( IFMXPhoneDialerService, FPhoneDialerService); // 전화걸기 서비스 end; procedure TForm1.Button1Click(Sender: TObject); begin PermissionsService.RequestPermissions([FPermissionLoacation], Loacation_PermissionRequestResult, DisplayRationale); end; procedure TForm1.Button2Click(Sender: TObject); begin PermissionsService.RequestPermissions([FPermissionCall], Call_PermissionRequestResult, DisplayRationale); end; procedure TForm1.Button3Click(Sender: TObject); begin PermissionsService.RequestPermissions([FPermissionCamera], Camera_PermissionRequestResult, DisplayRationale); end; procedure TForm1.DisplayRationale(Sender: TObject; const APermissions: TClassicStringDynArray; const APostRationaleProc: TProc); var I: Integer; RationaleMsg: string; begin for I := 0 to High(APermissions) do begin if APermissions[I] = FPermissionLoacation then RationaleMsg := RationaleMsg + 'The app needs to access the Permission Location' + SLineBreak + SLineBreak else if APermissions[I] = FPermissionCall then RationaleMsg := RationaleMsg + 'The app needs to access the Permission Call' + SLineBreak + SLineBreak else if APermissions[I] = FPermissionCamera then RationaleMsg := RationaleMsg + 'The app needs to access the Permission Camera'; end; // 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 TDialogService.ShowMessage(RationaleMsg, procedure(const AResult: TModalResult) begin APostRationaleProc; end) end; procedure TForm1.Loacation_PermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray); begin // 3 permissions involved: CAMERA, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE // if (Length(AGrantResults) = 3) and // (AGrantResults[0] = TPermissionStatus.Granted) and // (AGrantResults[1] = TPermissionStatus.Granted) and // (AGrantResults[2] = TPermissionStatus.Granted) then if ( Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then TDialogService.ShowMessage('Location permissions OK ' ) else TDialogService.ShowMessage('The required permissions are not granted'); end; procedure TForm1.Call_PermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray); begin if ( Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then begin TDialogService.ShowMessage('Call permissions OK ' ); BT_Call.Enabled := TRUE; end else TDialogService.ShowMessage('The required permissions are not granted'); end; procedure TForm1.Camera_PermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray); begin if ( Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then TDialogService.ShowMessage('Camera permissions OK ' ) else TDialogService.ShowMessage('The required permissions are not granted'); end; procedure TForm1.BT_CallClick(Sender: TObject); begin FPhoneDialerService.Call( '114' ); // 전화번호 end; end. 인용하기 이 댓글 링크 다른 사이트에 공유하기 더 많은 공유 선택 사항
Recommended Posts
이 토의에 참여하세요
지금 바로 의견을 남길 수 있습니다. 그리고 나서 가입해도 됩니다. 이미 회원이라면, 지금 로그인하고 본인 계정으로 의견을 남기세요.