Android-zxing Two-dimensional code scan encountered problems

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.