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 ();
}