Android

关注公众号 jb51net

关闭
首页 > 软件编程 > Android > Android实现银行卡号扫描识别

Android实现银行卡号扫描识别功能

作者:Jersey_me

这篇文章主要为大家详细介绍了Android实现银行卡号扫描识别功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

现在有好多扫描识别银行卡号的SDK都是收费的,但是也有不收费的,但是有一定的问题,就是那种印刷的银行卡号扫描不出来,希望哪位大神指导原因给解释下,这个不收费的SDK就是card.io-Android-SDK,githubdi地址

使用方式很简单,更多介绍可以看GitHub 使用文档

首先导入依赖:compile 'io.card:android-sdk:5.5.1'

然后在你需要调用拍照的地方加上一下:

Intent scanIntent = new Intent(this, CardIOActivity.class);

// customize these values to suit your needs.
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false); // default: false

// MY_SCAN_REQUEST_CODE is arbitrary and is only used within this activity.
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);

在onActivityForResult中接收结果:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);

  if (requestCode == MY_SCAN_REQUEST_CODE) {
    String result;
    if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
      CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);

      // Never log a raw card number. Avoid displaying it, but if necessary use getFormattedCardNumber()
      result = "Card Number: " + scanResult.getRedactedCardNumber() + "\n";

      if (scanResult.isExpiryValid()) {
        result += "Expiration Date: " + scanResult.expiryMonth + "/" + scanResult.expiryYear + "\n";
      }

      if (scanResult.cvv != null) {
        // Never log or display a CVV
        result += "CVV has " + scanResult.cvv.length() + " digits.\n";
      }

      if (scanResult.postalCode != null) {
        result += "Postal Code: " + scanResult.postalCode + "\n";

      }
    } else {
      result = "Scan was canceled.";
    }
    Log.e("resultdispalyStr----",result);

  }
}


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文