in short, I am making an application that if someone touches my cell phone, it sends a log to my computer, this log includes the date, time and 2 photos. I want my application to take 2 photos, one from the front camera and one from the rear camera, but how do I do that without the photo preview? I can't tell anyone on my cell phone "take a picture there for me". And, I have to do this all in the "OnPasswordFailed" and "OnPasswordSucceeded" methods of DeviceAdminReceiver, that is, in no screen, everything in the background. Is it possible to take a picture without a preview, in the background?
Actually, my code to take a picture is:
var p = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { DefaultCamera = CameraDevice.Front });
Answers
Do you want to achieve the result like following GIF?

You cannot use
CrossMedia
this plugin to achieve it. you should use Native Camera API to achieve it.I used the
SurfaceView
to achieve it, but I set thelayout_height
andlayout_width
to 1dp. it cannot be seen in the activity.Here is background code.
Here is my demo(Do not forget to add the permissions manually).
I will take a picture in the DeviceAdminReceiver, i don't have an activity or a button.
This is just a simple for your function(withOut button and activity, I cannot test it for you), You can create surfaceview by code in background service or broadCastReceiver.
getting System.NullReferenceException: 'Object reference not set to an instance of an object.'
in line var parameters = camera.GetParameters();