1. Perform the compile operation in the module's Build.gradle
Compile ' cn.yipianfengye.android:zxing-library:2.2 '
2. Perform initialization in demo application
@Override Public void onCreate () { super. OnCreate (); Zxinglibrary.initdisplayopinion (this); }
3. Perform open scan QR code interface operation
New Intent (mainactivity. this, captureactivity. class ); Startactivityforresult (Intent, Request_code);
The request_code here is our definition of the INT type constant
4. Receive the scan results in the activity's Onactivityresult method
/*** processing QR code scan results*/ if(Requestcode = =Request_code) { //processing Scan results (displayed on the interface) if(NULL!=data) {Bundle Bundle=Data.getextras (); if(Bundle = =NULL) { return; } if(Bundle.getint (codeutils.result_type) = =codeutils.result_success) {String result=bundle.getstring (codeutils.result_string); Toast.maketext ( This, "Parse Result:" +result, Toast.length_long). Show (); } Else if(Bundle.getint (codeutils.result_type) = =codeutils.result_failed) {Toast.maketext (mainactivity). This, "Parsing the QR code failed", Toast.length_long). Show (); } } }
Integrate the default QR Code scan page