Before written a two-dimensional code scanning demo, with the zxing frame, click to download, follow-up scanning two-dimensional code in some problems, such as the resolution of compressed images, adjust the size of the scan window and so on. Follow-up units required to do a scan login implementation, found that the difficulty is how to know that you are scanning this computer, the background must be acquired (background technical problems) and then this parameter to me, and then passed to the background, the background to determine the login can. This allows you to log in by passing a parameter directly after scanning. The effect is as follows:
Approximate code implementation: Scan Jump:
Scan login Acase r.id.tv_more_qr:if (Pventquickclick.isfastdoubleclick ()) {break;} Dialogutils.showcommonpopupwindow (context); Myapplication.checklogin (Context, new Appcallback () {@Overridepublic void Appcallback (String userid) {//TODO Auto-generated method Stubdialogutils.dismisscommonpopupwindow (); Intent opencameraintent = new Intent (context, CAPTUREACTIVITY.CLASS);//zing Framework class Startactivityforresult (opencameraintent,0);}); Break
Then the scan will return the results of the scan in Onactivityresult
@Overridepublic void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityresult ( Requestcode, ResultCode, data); if (ResultCode = = Getactivity (). RESULT_OK) {Bundle bundle = Data.getextras (); String Qrresult = bundle.getstring ("result"); Logutils.log_e ("Qrresult", qrresult); int scan= qrresult.indexof ("+");//tangent string judgment//Login if (scan>0) {string starts = Qrresult.substring (0, scan); String ends = qrresult.substring (scan+1, Qrresult.length ()); Logutils.log_e ("starts", starts+ "..." +ends), if (Ends.equals ("Qrlogin")) {Intent Intent = new Intent (context, Qrlogin.class);//Jump to confirm Login interface Intent.putextra ("Scanresult", starts); StartActivity (intent);}} else if (Stringutils.geturl (Qrresult)) {//is the HTML link to jump directly to the browser, such as apk download etc Intent Intent =new intent (); Intent.setaction ("Android.intent.action.VIEW"); Uri content_url =uri.parse (Qrresult); Intent.setdata (Content_url); StartActivity (intent);} else if (! Stringutils.geturl (Qrresult)) {Toast.maketext (getactivity (), "Sir, you can't find it!!! ", 0). Show ();}}}
Then jump to confirm login screen: Click to determine the parameters:
@Overrideprotected void Baseonclick (View v) {switch (V.getid ()) {case R.id.tv_qr_login://toast.maketext (qrlogin.this, "Login", 0). Show ();D Ialogutils.showcommonpopupwindow (qrlogin.this); linkedhashmap<string, string> get_checkqrcodelogin = new linkedhashmap<string, String> (); get_ Checkqrcodelogin.put ("Key", Myapplication.getuserstate ("Loginkey"));//Android fixed to 1get_checkqrcodelogin.put (" SessionID ", sessionid);//Android fixed to 1httpmanager.getcheckqrcodelogin (Get_checkqrcodelogin, New Netcallback () {@ Overridepublic void callback (String result) {Dialogutils.dismisscommonpopupwindow (); Logutils.log_e ("Getcheckqrcodelogin", result); final Checkqrcodelogin Checkqrcode = Jsonutils.getbeanfromjson (Result , Checkqrcodelogin.class), if (Checkqrcode.code.equals ("1")) {Toast.maketext (qrlogin.this, "login succeeded", 0). Show (); Finish ( );}}}); Break
This enables the QR code scan login, QR code demo download, solve the scan box size and picture compression problem
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android implementation QR Code scan login Page