Xamarin develops Android notes: continuous scanning with zxing

Source: Internet
Author: User

In the project development need to use to barcode scanning, because previously tested zxing, feeling recognition speed and function are good, so direct reference. However, in the actual development process, but encountered a continuous scanning problem, each scan recognition is completed, the scan form automatically closed.

Find the solution in the Xamarin forum and just find the solution for the iOS version. The solution for referring to iOS is to re-open the scan after the scan is complete. In this way, the idea of using intent for result is implemented. The implementation method is the following code:

Main form:

1 usingSystem;2 usingAndroid.app;3 usingandroid.content;4 usingAndroid.runtime;5 usingandroid.views;6 usingAndroid.widget;7 usingAndroid.os;8 usingZxing.mobile;9 Ten namespaceImstudio.qrcodelife One { A[Activity (Label ="Imstudio.qrcodelife", Mainlauncher =true)] -      Public classmainactivity:activity -     { the         intCount =1; -  -         protected Override voidOnCreate (Bundle bundle) -         { +             Base. OnCreate (bundle); -  +             //Set Our view from the "main" layout resource A Setcontentview (Resource.Layout.Main); at  -             //Get Our buttons from the layout resource, -             //And attach an event to it -             varbutton = findviewbyid<button>(Resource.Id.myButton); -             varTV = Findviewbyid<textview>(Resource.Id.textView1); -              inbutton. Click + =Async Delegate -             { toStartactivityforresult (typeof(CodeActivity),1); +             }; -         } the  *         protected Override voidOnactivityresult (intRequestcode, Result ResultCode, Intent data) $         {Panax Notoginseng             if(Requestcode = =1) -             { the                 if(ResultCode = =Result.ok) +                 { AFindviewbyid<textview> (Resource.Id.textView1). Text + = data. Getstringextra ("Code") +System.Environment.NewLine; theStartactivityforresult (typeof(CodeActivity),1); +                 } -             } $         } $     } -}

Subform, add a "finish" or "Cancel" button to close the Sweep code form, as follows:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingAndroid.app;usingandroid.content;usingAndroid.os;usingAndroid.runtime;usingandroid.views;usingAndroid.widget;namespaceimstudio.qrcodelife{[Activity (Label="CodeActivity")]     Public classcodeactivity:activity {protected Override Async voidOnCreate (Bundle bundle) {Base.            OnCreate (bundle); //Create your application here            varScanner =NewZXing.Mobile.MobileBarcodeScanner ( This); Scanner. Usecustomoverlay=true; varZxingoverlay = Layoutinflater.fromcontext ( This). Inflate (Resource.Layout.Code,NULL); varDonebutton = zxingoverlay.findviewbyid<button>(Resource.Id.buttonZxingDone); Donebutton.click+ = (sender, e) = ={scanner.                Cancel ();                Setresult (result.canceled);            Finish ();            }; Scanner. Customoverlay=Zxingoverlay; varresult =awaitscanner.            Scan ();        Handlescanresult (result); }        Private voidHandlescanresult (Zxing.result Result) {if(Result! =NULL) {Intent Intent=NewIntent (); Intent. PutExtra ("Code", result.                Text);                Setresult (result.ok,intent);            Finish (); }        }    }}

Implementation code Although some rough, but functional OK, first use, back to think there is no good way.

Xamarin develops Android notes: continuous scanning with zxing

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.