A lite version of the QR code for Android with Zxing.jar (simplified configuration and code)

Source: Internet
Author: User

Recently, the company made a OTP token activation product, because the previous activation of the phone token requires the input of a lot of activation information to activate.     After a period of use, it is found that the usability is not very strong, consider if adding QR code of the scanning function is not greatly increased ease of use. Search on the Internet a lot of information, but not too much configuration, or the code is too large, and finally no way to bite the bullet to write and to streamline, and finally compressed to the current version. If you have a better version, you can contact me.

Specific demo can be downloaded by download http://download.csdn.net/detail/fugui6611634/7341277

The results of this article's code run are as follows:

The structure of the code is as follows:

Here's a look at the configuration file:

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" com.ft "android:versioncode=" 1 "android:versionname=" 1.0 "> <application android: icon= "@drawable/icon" android:label= "@string/app_name" > <activity android:name= ". Twocodeactivity "android:label=" @string/app_name "> <intent-filter> &lt Action android:name= "Android.intent.action.MAIN"/> <category android:name= "android.intent.category. LAUNCHER "/> </intent-filter> </activity> <activity android:name=" Com.go Ogle.zxing.ui.CaptureActivity "android:configchanges=" Keyboardhidden|orientation "Android:screenorie        ntation= "Landscape" android:windowsoftinputmode= "Adjustresize|statealwayshidden"/> </application> &LT;USES-SDK android:minsdkversion= "3"/> <uses-perMission android:name= "Android.permission.READ_PHONE_STATE"/> <uses-permission android:name= " Android.permission.INTERNET "/> <uses-permission android:name=" Android.permission.WAKE_LOCK "/>< Uses-permission android:name= "Android.permission.DEVICE_POWER"/><uses-permission android:name= " Android.permission.CAMERA "/><uses-permission android:name=" Android.permission.VIBRATE "/>< Uses-permission android:name= "Android.permission.FLASHLIGHT"/><uses-permission android:name= " Android.permission.WRITE_EXTERNAL_STORAGE "/><uses-feature android:name=" Android.hardware.camera "/> <  Uses-feature android:name= "Android.hardware.camera.autofocus"/> </manifest>


Startup class Twocodeactivity.java

Package Com.ft;import Android.app.activity;import Android.app.alertdialog;import android.content.intent;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.Button; Import Android.widget.textview;import Com.google.zxing.ui.captureactivity;public class Twocodeactivity extends    Activity {public static final int scan_code = 1;    Alertdialog.builder alertdialog = null; /** called when the activity is first created.        */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);                Setcontentview (R.layout.main);        Button button = (button) This.findviewbyid (R.id.scan);                Button.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {                Intent Intent = new Intent (twocodeactivity.this, Captureactivity.class);            Startactivityforresult (Intent, Scan_code); }                    });                  } @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {        TextView TextView = (TextView) This.findviewbyid (R.id.mytext); Switch (requestcode) {case Scan_code:if (ResultCode = = RESULT_OK) {String RESULT = dat                A.getstringextra ("Scan_result");            Textview.settext ("Scan succeeded:" +result);            } else if (ResultCode = = result_canceled) {textview.settext ("Scan failed:");        } break;        Default:break; }    }}


 

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.