Use the default mode Open the default QR code scanning interface: Intent Intent = new Intent (Getapplication (), captureactivity.class); Startactivityforresult (Intent, Request_code); Accept the result @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) { /** * 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); Tvscanmsg.settext (result); Toast.maketext (This, "parse Result:" + result, Toast.length_long). Show (); } else if (Bundle.getint (codeutils.result_type) = = codeutils.result_failed) { Toast.maketext (Mcontext, "Parsing the QR code failed", Toast.length_long). Show (); } } } } Custom mode Add capturefragment Replace scan layout area Capturefragment = new Capturefragment (); Set up a custom interface for QR code scanning interface Codeutils.setfragmentargs (Capturefragment, r.layout.scan_area_layout); Capturefragment.setanalyzecallback (Analyzecallback); Getsupportfragmentmanager (). BeginTransaction (). replace (R.id.fl_scan_area, capturefragment). commit (); Customizing the scan layout <?xml version= "1.0" encoding= "Utf-8"?> <framelayout xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns:app= "Http://schemas.android.com/apk/res-auto" Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" > <surfaceview Android:id= "@+id/preview_view" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" /> <com.uuzuche.lib_zxing.view.viewfinderview Android:id= "@+id/viewfinder_view" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" App:inner_width= "200DP" app:inner_height= "200DP" app:inner_margintop= "25DP" App:inner_corner_color= "@color/red" App:inner_corner_length= "30DP" App:inner_corner_width= "5DP" app:inner_scan_bitmap= "@drawable/scan_image" App:inner_scan_speed= "10" App:inner_scan_iscircle= "false" /> </FrameLayout> Processing of scan result callbacks /** * Two-dimensional code parsing callback function */ Codeutils.analyzecallback analyzecallback = new Codeutils.analyzecallback () { @Override public void Onanalyzesuccess (Bitmap mbitmap, String result) { FWLOG.D (result); Onscanfinish (result); } @Override public void onanalyzefailed () { FWLOG.D ("Failed ..."); Onscanfinish (""); } }; private void Onscanfinish (String result) { Intent resultintent = new Intent (); Bundle bundle = new bundle (); Bundle.putint (Codeutils.result_type, codeutils.result_success); Bundle.putstring (codeutils.result_string, RESULT); Resultintent.putextras (bundle); Setresult (RESULT_OK, resultintent); Finish (); } |