We are developing an app for the Vuzix M100, which should continuously read a barcode and display the result in a textView. Therefore, the camera takes a picture every 5 seconds and sends the bitmap to the zxing barcode scanner. We are almost done, but the camera is only focusing at the first picture. Any suggestions? This is the important part of our code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView1);
mPreview = (SurfaceView) findViewById(R.id.sv1);
mPreview.getHolder().addCallback(this);
mCamera = Camera.open();
final Parameters param = mCamera.getParameters();
param.setJpegQuality(100);
param.setPictureSize(1600, 1200);
param.setFocusMode(param.FOCUS_MODE_CONTINUOUS_PICTURE);
param.setSceneMode(Parameters.SCENE_MODE_BARCODE);
mCamera.setParameters(param);
final Handler h = new Handler();
final int delay = 5000;
h.postDelayed(new Runnable(){
int count = 1;
public void run(){
tryAutoFocus();
param.setFocusMode(param.FOCUS_MODE_FIXED);
param.setFocusMode(param.FOCUS_MODE_AUTO);
h.postDelayed(this, delay);
}
}, delay);
}
.
private void tryAutoFocus() {
final PictureCallback myPictureCallback = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length, options);
createExternalStoragePublicPicture(bmp);
} catch (Exception e) {
e.printStackTrace();
}
}
};
AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera arg1) {
// TODO: Problem: Fokussiert nur beim ersten Foto
mCamera.takePicture(null, null, null, myPictureCallback);
mCamera.cancelAutoFocus();
mCamera.startPreview();
}
};
mCamera.autoFocus(myAutoFocusCallback);
}