Recent work needs to develop a QR code scanning software (based on open source project zxing), the problems encountered in the record, but also hope to bring you help.
1. First because the scan to open the camera so add permission is certain, otherwise nothing can be done behind
<uses-permission android:name= "Android.permission.CAMERA"/>
2. Set the size of the scan box:
Find in the Com.zxing.camera package
private static final int min_frame_width = 240;
private static final int min_frame_height = 240;
private static final int max_frame_width = 580;
private static final int max_frame_height = 580;
Modify these property values to modify the size of the scan box.
3. Realize the double scan of QR code
1. Find the Restartpreviewanddecode () method in the Com.zxing.decoding package, which itself is private to public
2. Add a duplicate scan method to the activity that scans the QR code:
private void Continuepreview () {
Surfaceview Surfaceview = (surfaceview) Findviewbyid (R.id.preview_view);
Surfaceholder Surfaceholder = Surfaceview.getholder ();
Initcamera (surfaceholder);
if (handler! = null) {
Handler.restartpreviewanddecode ();
}
Note: Sometimes a bug occurs when you call this method directly: a black screen appears when you return to the previous interface again after multiple scans.
Workaround: do not directly call Continuepreview () This method, when the need to scan two times directly write:
if (handler! = null) {
Handler.restartpreviewanddecode ();
}
Android-zxing Two-dimensional code scan encountered problems