In Android, ZXing. jar is used to identify the simplified version of the QR code (simplified configuration and code)

Source: Internet
Author: User

Recently, the company made an OTP token activation product. Because the mobile phone token was activated before, a lot of activation information needs to be entered for activation. After a period of use, it is found that the ease of use is not very strong, consider if you add the QR code scanning function does not greatly increase the ease of use. I found a lot of information on the Internet. If it weren't for too many configurations, or the amount of code was too large, I couldn't just write and streamline it, and finally compress it to the current version. If you have a better version, contact me.

For specific demos, download http://download.csdn.net/detail/fugui66000034/7341277.

The result of code execution in this article is as follows:

The code structure is as follows:

The configuration file is as follows:

 
                         
                                  
               
                          
      
      
      
  
  
  
  
  
  
    
   
  


Start 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 = data. getStringExtra ("scan_result"); textView. setText ("Scan successful:" + result);} else if (resultCode = RESULT_CANCELED) {textView. setText ("Scan failed:") ;}break; default: break ;}}}


Related Article

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.