Example tutorial of Android using zxing to quickly integrate QR code scanning

preface

Everyone should remember that in the past, we used to scan bar codes. Since wechat used QR codes to scan, now the market basically uses QR codes to scan. Basically, every project will have a QR code scan. This article will simply and quickly achieve a scanning effect, Let us have a preliminary understanding of QR code scanning and let our project quickly integrate the function of QR code scanning. I won't say much now. Let's take a look at the detailed introduction.

Implementation method:

1. First, we need to import some dependency libraries in our gradle file

2. After integration, we can use it directly. The code is very simple.

By calling these methods, we can realize scanning. Let's talk about the functions of these methods. Setdesiredbarcodeformats () is the scanned barcode type, one_ D_ CODE_ Types represents one-dimensional code, QR_ CODE_ Types represents the QR code.

Setprompt() is the text for setting the scanning interface.

setCameraId(); Is to set the type of camera to open, that is, 0 represents horizontal screen, 1 represents vertical screen, and 2 represents the interface for scanning barcode

Setbeepenabled() is to set whether there will be sound after the scan is completed.

InitiateScan () is a last call method, by calling it to achieve the jump of the interface, it calls startActivityForResult () internally. To open the camera interface.

3. Get the results of our scan

As shown above, its returned result is in onactivityresult(). Call the parseactivityresult() method to get our scanning results, and then call getcontents() to get the contents of our scanning results.

The above is an example of fast integration zxing to realize QR code scanning, which can easily and quickly realize the function of QR code scanning.

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>