Reputation: 41
I'm writing an android app. I encounter the following problem:
app passed NULL surface
while executing the following code:
public void takePictureNoPreview(Context context){
try {
myCamera = Camera.open(0);
} catch (Exception e) {
e.printStackTrace();
console.append("Failed to connect to camera\n");
}
if(myCamera!=null){
SurfaceView dummy=new SurfaceView(context);
try {
myCamera.setPreviewDisplay(dummy.getHolder());
myCamera.startPreview();
myCamera.takePicture(null, null, getJpegCallback());
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
myCamera.stopPreview();
myCamera.release();
}
}
The main goal is to take a picture without the surfaceview, in order to store it and send via email as quickly as possible.
Thanks in advance.
Upvotes: 2
Views: 7587
Reputation: 1575
I think you should implement the interface SurfaceHolder.Callback first, and then add callback to the holder first, e.g.
mHolder.addCallback(callback)
myCamera.setPreviewDisplay(mHolder);
myCamera.startPreview();
I think it will be ok!!
If you have any problems, you can refer to 1.my https://github.com/RyanLiuNtust/Lecture-of-Android/tree/camera_lecture
Upvotes: 3
Reputation: 11
You can't do it. There are some privacy issues with the camera. I have seen this answer on one of the boards here before but I don't have time to look that answer up again. You can't do it, because if your app takes a picture of something they should be able to know what it is of.
Upvotes: 0