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

2020-11-05 11:20:40 浏览数 (1)

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

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

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

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

代码语言:javascript复制
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中接收结果:

代码语言:javascript复制
@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);

  }
}

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

0 人点赞