I have some codes of taking picture which works in Android 2.1 and 2.2. But these codes broke at Android 2.3. After spending time to fix this issue which went in vain, I wou
I ran into this issue with GB phones, and for me, it turned out to be because I was calling camera.startPreview() right after calling camera.takePicture(), and this was causing some thread locking in Android. The fix was to move camera.startPreview() into the callback passed into camera.takePicture(), such that it only got called once the picture data was in (example code below). This is of course only relevant if you're interested in restarting the preview after the picture is taken.
// BAD BAD DON'T DO THIS!
public void myTakePicture(Camera.PictureCallback callback) {
mCamera.takePicture(null, null, null, callback);
mCamera.startPreview();
}
// ...
// The way that worked for me
public void myTakePicture(final Camera.PictureCallback callback) {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] pictureData, Camera camera) {
callback.onPictureTaken(pictureData, camera);
mCamera.takePicture();
}
});
}
This not only made the ANR go away when calling takePicture, but also fixed a native crash on startPreview that was happening on some higher end phones (particularly a >=4.3 Nexus 5). Hope it helps!