Jump to content
Peter J.

Using Camera in Android 9 under Delphi 12.1 CE

Recommended Posts

I used this for Delphi 11.x with Android 9. No issue.  Now the same code in Delphi 12.1 crashes

after I "allow camera" in Android phone.  Permissions [x] Camera.  I even enabled "Secured File Sharing" just to be safe.
Any advice?  A similar service for Select Photos From Folder (IFMXTakenImageService) does not crash.

Any advice on this?

var
  Params: TParamsPhotoQuery;
begin

  if TPlatformServices.Current.SupportsPlatformService(IFMXCameraService,
    FCameraService) then
  begin
    Params.Editable := False;
    Params.NeedSaveToAlbum := False;
    Params.RequiredResolution := TSize.Create(640,640);
    Params.OnDidFinishTaking := TakePhotoDidFinishTaking;
    Params.OnDidCancelTaking := DoCancelTaking;
    FCameraService.TakePhoto(button1, Params);
  end else
  begin


  end;

Share this post


Link to post
5 hours ago, Peter J. said:

Now the same code in Delphi 12.1 crashes

I suppose you know that Android 9 is not supported by Delphi 12.

A log or a message of the error would help to have a better response.

Share this post


Link to post

oh, thanks for the response!  I didn't know that Android 9 is not supported.

Delphi 12 Athens is here! – Delphi Worlds
-> it says Android 8.1  so I'm a little confused.

 

There's no error. click the button to take photo and the app closes.  As for the adb log,

it is way too many, so I didn't think it would be useful.

 

I'll try to get a newer Android phone.  Meanwhile, if anyone has similar experiences, please let me know possible solutions.

 

thank you!

Share this post


Link to post
2 hours ago, Peter J. said:

Delphi 12 Athens is here! – Delphi Worlds
-> it says Android 8.1  so I'm a little confused.

https://docwiki.embarcadero.com/RADStudio/Athens/en/Supported_Target_Platforms

 

Maybe 12.0 supported Android 8.1 but 12.2 not.

And if you filter the log only for your app at the and in the last page(s) should be some clues for why app closes.

Share this post


Link to post
10 hours ago, Cristian Peța said:

I suppose you know that Android 9 is not supported by Delphi 12.

That's "official" support. Theoretically, Delphi 12 can be used to create apps that run on Android 5 or later.

6 hours ago, Peter J. said:

There's no error. click the button to take photo and the app closes.

Does the camera not appear at all, or is it once you've taken a photo? If the latter, you should show your code for TakePhotoDidFinishTaking. A complete test case would be even better

6 hours ago, Peter J. said:

As for the adb log, it is way too many, so I didn't think it would be useful.

Just because there's a lot of messages, it does not mean it is not useful. Use filtering to see only relevant messages. This link might help.

Share this post


Link to post
14 hours ago, Dave Nottage said:

That's "official" support. Theoretically, Delphi 12 can be used to create apps that run on Android 5 or later.

Does the camera not appear at all, or is it once you've taken a photo? If the latter, you should show your code for TakePhotoDidFinishTaking. A complete test case would be even better

Just because there's a lot of messages, it does not mean it is not useful. Use filtering to see only relevant messages. This link might help.

Thanks for the reply.  The camera did not show at all.  The app crashed as in "closed without error message".

 

procedure TForm2.DidCancelTaking(const Sender: TObject; const M: TMessage);
begin
  if M is TMessageDidCancelTaking then
  begin
    DoCancelTaking;
    // do cancellation stuff
  end;
end;

procedure TForm2.DoCancelTaking;
begin
  //if Assigned(OnDidCancelTaking) then
  //Memo1.lines.insert(0,'cancel taking photo');
end;

procedure TForm2.RequestCameraPermissions;
begin
  PermissionsService.RequestPermissions(['android.permission.CAMERA'],
                        PermissionsResult,
                        nil);
end;

 

procedure TForm2.PermissionsResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray);
//PermissionsResult
begin
  //if AGrantResults = TPermissionResult.GRANTED then
  if (Length(AGrantResults) = 1)
     and (AGrantResults[0] = TPermissionStatus.Granted) then
  begin
    // Permissions granted, start the camera
    // CameraComponent1.Active := True;

    takephoto();
    //TakePhotoFromCameraAction1.Execute;
    showmessage('executed');
  end
  else
  begin
    // Permissions denied, show a message
    ShowMessage('Camera permission is required to use this feature.');
  end;
end;

procedure TForm2.takephoto();
var
  Params: TParamsPhotoQuery;
begin

  if TPlatformServices.Current.SupportsPlatformService(IFMXCameraService, FCameraService) then

  begin
    Params.Editable := False;
    Params.NeedSaveToAlbum := False;
    Params.RequiredResolution := TSize.Create(640,640);
    Params.OnDidFinishTaking := TakePhotoDidFinishTaking;
    Params.OnDidCancelTaking := DoCancelTaking;
    FCameraService.TakePhoto(button1, Params);
  end else
  begin


  end;

end;

 

procedure TForm2.TakePhotoFromCameraActionDidFinishTaking(Image: TBitmap);
begin
  Image2.Bitmap.Assign(Image);
  showmessage('TakePhotoFromCameraActionDidFinishTaking()');
end;
 

Share this post


Link to post
8 hours ago, Peter J. said:

The camera did not show at all.

Have you tried viewing the log messages as per my last reply?

Share this post


Link to post

Thanks for the reply, Dave.

 

sorry, I've been too overwhelmed to look into the log msg as it seems quite a lot of setup.

 

Anyway, I ran the same code in Android 15 and it worked fine!

 

It's quite disappointing though that it worked in 15 and not 9.  How would I know if my app

will work on Android 10-14?  Surely it's not practical to test all.

Share this post


Link to post
6 hours ago, Peter J. said:

It's quite disappointing though that it worked in 15 and not 9.  How would I know if my app

will work on Android 10-14?

Without the log messages, or a complete, reproducible example, it's going to be hard to tell.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×