??????? 近期公司做了一款OTP令牌激活的产品,因为之前激活手机令牌须要输入非常多的激活信息才干进行激活。
经过一段使用后,发现易用性不是非常强,考虑假设添加二维码的的扫码功能岂不是大大添加了易用性。
???? 在网上搜了非常多资料,要不是配置太多,要不就是代码量太大。最后没办法就硬着头皮去写和去精简,最后压缩至眼下的版本号。
假设有更好的版本号能够联系我。??
? ???
??????? 详细DEMO能够通过 下载http://download.csdn.net/detail/fugui6611634/7341277下载
??????? 本文代码执行的结果例如以下:
??????
?
????? 代码的结构例如以下:
?
??????? 以下主要来看一下配置文件:
????????
<?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>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.ui.CaptureActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
</application>
<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>
?
?
???? 启动类 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("扫描成功:"+result);
} else if (resultCode == RESULT_CANCELED) {
textView.setText("扫描失败:");
}
break;
default:
break;
}
}
}
?