I am using Zbar for reading QRCode. I use this https://github.com/DushyanthMaguluru/ZBarScanner example for my activity. The Question is how can I show cameraView on my FrameLa
First of all remove the line that seems to me to acquire camera access: mCamera = getCameraInstance();
. You don't want to do that as the CameraPreview
will do it for you.
I wouldn't use a FrameLayout as items are put one after the other and you want to put your cameraPreview at last. So you should have a LinearLayout
in another RelativeLayout
(I know, it's not efficient, but that's fine for now). Something like (your main.xml layout):
Now, you would need to put the CameraPreview in zbar_layout_area
. For this reason, try to change the code to (blind coding):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!isCameraAvailable()) {
// Cancel request if there is no rear-facing camera.
cancelRequest();
return;
}
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
mAutoFocusHandler = new Handler();
// Create and configure the ImageScanner;
setupScanner();
// Create a RelativeLayout container that will hold a SurfaceView,
// and set it as the content of our activity.
mPreview = new CameraPreview(this, this, autoFocusCB);
LinearLayout zbarLayout = (LinearLayout) findViewById(R.id.zbar_layout_area);
mPreview.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
zbarLayout.addView(mPreview);
}
Also make sure you have set enough prermissions: