How to get image from Android library using Firemonkey?

  

In Delphi 10.4, I try to select image from the Android library.
I’m not inventing anything, it take this from Embarcadero’s DocWiki. I ask the user for permissions in another button without any problem.
procedure TForm1.MyButtonClick(Sender: TObject);
var
ImageService: IFMXTakenImageService;
Params: TParamsPhotoQuery;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXTakenImageService, ImageService) then
begin
Params.RequiredResolution := TSize.Create(640, 640);
Params.OnDidFinishTaking := DoDidFinish;
ImageService.TakeImageFromLibrary(MyButton, Params);
end;
end;

When I execute it, I get a "class exception 6" error:
procedure TImageManagerAndroid.TakeImageFromLibrary(const AControl: TControl; const AParams: TParamsPhotoQuery);
begin
if AParams.Editable then
begin
if not PermissionsService.IsPermissionGranted(JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE)) then
raise EPermissionException.CreateFmt(SRequiredPermissionsAreAbsent, [‘WRITE_EXTERNAL_STORAGE’]);
end
else
begin
if not PermissionsService.IsPermissionGranted(JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE)) then
raise EPermissionException.CreateFmt(SRequiredPermissionsAreAbsent, [‘READ_EXTERNAL_STORAGE’]);
end;

FParams := AParams;
FParams.RequiredResolution := ApproximateAdmissibleImageSize(FParams.RequiredResolution);
MainActivity.getMediaLibrary.takeImageFromLibrary(FParams.RequiredResolution.Width, FParams.RequiredResolution.Height,
FParams.Editable); // <– here
end;

Did I need to do something to make this work?

Comments are closed.