Android 银行卡扫描识别获取卡号
2016-04-15 16:54
726 查看
用card.io 实现的银行卡扫描,免费
Card.io是让手机摄像头获取信用卡的信息,中间利用了OCR(光学字符识别)的扫描技术返回结果,它还推出了SDK(软件开发包),让开发者们可以把card.io添加到自己的应用当中。
主要类:
public class MyScanActivity extends Activity
{
final String TAG = getClass().getName();
private Button scanButton;
private TextView resultTextView;
private int MY_SCAN_REQUEST_CODE = 100;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
resultTextView = (TextView)findViewById(R.id.resultTextView);
scanButton = (Button)findViewById(R.id.scanButton);
resultTextView.setText("扫描银行卡: " + CardIOActivity.sdkVersion() + "\nBuilt: " + CardIOActivity.sdkBuildDate());
}
@Override
protected void onResume() {
super.onResume();
if (CardIOActivity.canReadCardWithCamera(this)) {
scanButton.setText("Scan a credit card with card.io");
}
else {
scanButton.setText("Enter credit card information");
}
}
public void onScanPress(View v) {
Intent scanIntent = new Intent(this, CardIOActivity.class);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false);
// scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, false);
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, true);//是否显示右下角键盘输入,为不显示
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String resultStr;
if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);
resultStr = "Card Number: " + scanResult.getRedactedCardNumber() + "\n";
if (scanResult.isExpiryValid()) {
resultStr += "Expiration Date: " + scanResult.expiryMonth + "/" + scanResult.expiryYear + "\n";
}
if (scanResult.cvv != null) {
resultStr += "CVV has " + scanResult.cvv.length() + " digits.\n";
}
if (scanResult.postalCode != null) {
resultStr += "Postal Code: " + scanResult.postalCode + "\n";
}
}
else {
resultStr = "Scan was canceled.";
}
resultTextView.setText(resultStr);
}
资源下载:
eclipse上面运行的Demo:
http://download.csdn.net/detail/liqingmiao123/9492343
AndroidStudio上运行的Demo:
http://download.csdn.net/detail/rjliulei/8766921
Card.io是让手机摄像头获取信用卡的信息,中间利用了OCR(光学字符识别)的扫描技术返回结果,它还推出了SDK(软件开发包),让开发者们可以把card.io添加到自己的应用当中。
主要类:
public class MyScanActivity extends Activity
{
final String TAG = getClass().getName();
private Button scanButton;
private TextView resultTextView;
private int MY_SCAN_REQUEST_CODE = 100;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
resultTextView = (TextView)findViewById(R.id.resultTextView);
scanButton = (Button)findViewById(R.id.scanButton);
resultTextView.setText("扫描银行卡: " + CardIOActivity.sdkVersion() + "\nBuilt: " + CardIOActivity.sdkBuildDate());
}
@Override
protected void onResume() {
super.onResume();
if (CardIOActivity.canReadCardWithCamera(this)) {
scanButton.setText("Scan a credit card with card.io");
}
else {
scanButton.setText("Enter credit card information");
}
}
public void onScanPress(View v) {
Intent scanIntent = new Intent(this, CardIOActivity.class);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false);
// scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, false);
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, true);//是否显示右下角键盘输入,为不显示
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String resultStr;
if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);
resultStr = "Card Number: " + scanResult.getRedactedCardNumber() + "\n";
if (scanResult.isExpiryValid()) {
resultStr += "Expiration Date: " + scanResult.expiryMonth + "/" + scanResult.expiryYear + "\n";
}
if (scanResult.cvv != null) {
resultStr += "CVV has " + scanResult.cvv.length() + " digits.\n";
}
if (scanResult.postalCode != null) {
resultStr += "Postal Code: " + scanResult.postalCode + "\n";
}
}
else {
resultStr = "Scan was canceled.";
}
resultTextView.setText(resultStr);
}
资源下载:
eclipse上面运行的Demo:
http://download.csdn.net/detail/liqingmiao123/9492343
AndroidStudio上运行的Demo:
http://download.csdn.net/detail/rjliulei/8766921
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories