I need to take a picture with the back camera in an android service but after reading the docs it seems you need a SurfaceView
is it possible to take a picture without showing anything to the user?
Edit: Will this work?
SurfaceTexture surfaceTexture = new SurfaceTexture(10);
Camera camera = Camera.open();
camera.getParameters().setPreviewSize(1, 1);
camera.setPreviewTexture(surfaceTexture);
camera.startPreview();
camera.takePicture(null, pictureCallback, null);
You can set Width
and Height
of SurfaceView
to 1dp
and margintop
to -10
,so that it wont display it on screen but it functions as normal and you can Take picture without displaying Surface View to User
<SurfaceView
android:layout_width="1dp"
android:layout_height="1dp"
android:layout_marginTop="-10dp"
...
/>
in that case you can just use SurfaceTexture
SurfaceTexture surfaceTexture = new SurfaceTexture(10);
Camera camera = Camera.open();
camera.getParameters().setPreviewSize(1, 1);
camera.setPreviewTexture(surfaceTexture);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments