用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:
/detail/liqingmiao123/9492343
AndroidStudio上运行的Demo:
/detail/rjliulei/8766921