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 ;}}}