Android-ZXing QR code scanning problems, androidzxing

Source: Internet
Author: User

Android-ZXing QR code scanning problems, androidzxing

In recent work, we need to develop software with the QR code scanning function (based on the ZXing open-source project). Record the problems and hope to help you.

1. First, because scanning requires camera activation, you must add permissions. Otherwise, nothing can be done later.

<Uses-permission android: name = "android. permission. CAMERA"/>

2. Set the scan box size:

Search for 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 attribute values to modify the scan box size.

3. Implement repeated scanning of QR codes

1. Find the restartPreviewAndDecode () method in the com. zxing. decoding package, and change private to public.

2. Add the repeated 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 directly call this method: after multiple scans, a black screen will appear when you return to the previous interface and enter again.

Solution: if you do not directly call the continuePreview () method, write it directly when you need a second scan:

If (handler! = Null ){
Handler. restartPreviewAndDecode ();
}

 

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.