适用于Android的card.io SDK 扫描银行卡

card.io在移动应用程序中提供快速,轻松的信用卡扫描。

集成说明

1.卡片扫描要求

  • 后置摄像头。
  • Android SDK版本16(Android 4.1)或更高版本。
  • armeabi-v7a,arm64-v8,x86或x86_64处理器。

为不满足这些要求的设备提供手动输入回退模式。

2.添加依赖

compile 'io.card:android-sdk:5.5.1'

3.添加权限及设置AndroidManifest.xml文件

<!-- Permission to vibrate - recommended, allows vibration feedback on scan (扫描振动权限)-->
<uses-permission android:name="android.permission.VIBRATE" />

<!-- Permission to use camera - required (相机权限)-->
<uses-permission android:name="android.permission.CAMERA" />

<!-- Camera features - recommended -->
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />
<activity android:name="io.card.payment.CardIOActivity" android:configChanges="keyboardHidden|orientation" />
<activity android:name="io.card.payment.DataEntryActivity" />

4.示例代码

 1.设定一个按钮或其他组件来监听它的点击事件:

 @OnClick({R.id.btn_scan})
    public void setOnClick(View view) {
        switch (view.getId()) {
            case R.id.btn_scan:
                Intent scanIntent = new Intent(getActivity(), 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

                startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
                break;
        }
    }

2.重写OnActivityResult(),去获得扫描结果

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

        if (requestCode == MY_SCAN_REQUEST_CODE) {
            String resultDisplayStr;
            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()
                resultDisplayStr = "Card Number: " + scanResult.getRedactedCardNumber() + "\n";

                // Do something with the raw number, e.g.:
                // myService.setCardNumber( scanResult.cardNumber );

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

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

                if (scanResult.postalCode != null) {
                    resultDisplayStr += "Postal Code: " + scanResult.postalCode + "\n";
                }
            } else {
                resultDisplayStr = "Scan was canceled.";
            }
            Log.i("resultDisplayStr",resultDisplayStr);
            // do something with resultDisplayStr, maybe display it in a textView
            // resultTextView.setText(resultDisplayStr);
        }
        // else handle other activity results
    }

5.效果图

git地址:https://github.com/card-io/card.io-Android-SDK

没有更多推荐了,返回首页