I am working with such a great library zxing to read QR code. I already got QR code successfully.
Now, My application runs in landscape mode and camera takes the whole screen and red QR detection rectangle box is in the middle. I wanna change this to portrait mode & replace the camera view only with the red QR detection rectangle box.
I change CaptureActivity tag which is inside the zxing library manifest file.
android:screenOrientation="portrait"
.
But found nothing what I actually want. I don't know where I have to change/write code to get this.
I was in same problem and got stuck about 2 days on it. Actually you have to do some tasks to achieve your goal.
Your main.xml file should look like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal">
<include layout="@layout/capture"/>
</FrameLayout>
</LinearLayout>
Your main Activity should look like:
public class ScannerActivity extends CaptureActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void handleDecode(Result rawResult, Bitmap barcode)
{
Toast.makeText(this.getApplicationContext(), "Scanned code " + rawResult.getText(), Toast.LENGTH_LONG).show();
}
}
In the manifest file add permission following:
<uses-permission android:name="android.permission.CAMERA"/>
and finally very IMPORTANT task you need to do for camera rotation problem, replace the following method into the
CameraManager.java (in the package com.google.zxing.client.android.camera)
@SuppressLint("NewApi") public void startPreview() {
Camera theCamera = camera;
if (theCamera != null && !previewing) {
theCamera.setDisplayOrientation(90);
theCamera.startPreview();
previewing = true;
}
}
that's all . run and enjoy :-)
thanks..