Getting started with Android: zxing Study Notes (1)

Source: Internet
Author: User

If a simple and comprehensive Android project can be analyzed, zxing is a good example.

The source code of zxing can be downloaded from Google Code. The entire source code is checked out, which contains the source code of each platform, iOS and Android. Of course, we need Android code. Import the android project to eclipse. After the import is complete, eclipse will display various errors, which are caused by the lack of core library files in the core folder. Create a folder core in the project, then, import the code from the core folder in the zxing source code. If you encounter unable resolved target-X, it is your AVD version problem. You can modify the target value in project. propertities. Under clean, click OK. The above are preparations for zxing Android code analysis, and the following is the official start.

For example, for the code of the entire android project, start with the code. The main concern is the Android, camera, encode, and result folders. Program startup process: load the main activity, and create the captureactivityhandler object in this class. This object starts the camera, implements automatic focus, creates a decodethread thread, and decodethread creates decodehandler, this object obtains the original byte data obtained from the camera, starts the first step of decoding, parses the QR map from the obtained byte, and parses the characters in the QR map, send this unanalyzed character to handle in captureactivityhandler. This class calls the decode function of main activity to analyze the character and display it on the interface (refresh the UI, it is best to complete it in the UI thread ). This process of parsing a QR map is complete. The following describes the entire process. The key points are the main activity. The first activity started by the camera program is captureactivity, which is somewhat similar to the main function in C. Here is the main activity. The main task of acitvity is to load and scan various bar codes, a QR code interface, start a thread for processing and obtaining the QR code information, and complete decoding of the obtained image information, finally, the decoded information is displayed on the interface. The loading of the completed interface mainly involves the oncreate and onresume functions. This involves the lifecycle of an activity and will be analyzed in detail later. Call oncreate first, and then onresume. In onresume, you can determine the start of the activity. It may be triggered by other apps or directly started by the user. In this way, three variables are initialized. One is source, which is the source for starting activity, the other is decodeformats, indicating the decoding method, such as QR code or other variables. The last one is: charactreset is used to encode the characters that generate the QR map. If the code in the core is not modified, the characters encoded by gb2312 will be garbled with this program. The solution to garbled code will be mentioned later. There are two key classes in interface loading. Surfaceview and viewfinderview are used to load the image of the camera image obtained from the underlying hardware, followed by a custom view, enabling the interface during scanning and constant refreshing, and display the identified data, such as the point callback on the interface.
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.