当前位置: 首页 > 工具软件 > card.io > 使用案例 >

Android笔记(翻译):card.io SDK for Android银行卡扫描

胥英奕
2023-12-01

card.io 提供快速,易于信用卡扫描在移动应用程序。

集成说明:
卡片扫描的要求
1.配置有后置的摄像头
2.Android系统在Android2.2以上,SDKversin8
可以手动输入银行卡号满足硬件设备不足的设备
集成开始

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

如果你使用其他的一些gradle,可以这样操作:
1。编辑AndroidMainfest.xml,如下

<uses-sdk android:minSdkVersion="8" />

2.在清单文件中添加以下权限和功能

<!-- 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" />

3.继续编辑清单文件,添加需要的Activity

<!-- Activities responsible for gathering payment info -->
<activity android:name="io.card.payment.CardIOActivity" android:configChanges="keyboardHidden|orientation" />
<activity android:name="io.card.payment.DataEntryActivity" />

示例代码:
首先我们需要设定一个按钮或其他组件来监听它的点击事件,布局文件的Button的Onclick=“onScanPress”然后添加以下方法:

public void onScanPress(View v) {
    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);
}

接下来,我们重写OnActivityResult(),去获得扫描结果:

@Override
protected 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.";
        }
        // do something with resultDisplayStr, maybe display it in a textView
        // resultTextView.setText(resultDisplayStr);
    }
    // else handle other activity results
}

提示与技巧

1.这里提供javadocs完整的提供参考
2.注意:正确的proguard文件自动导入到您的项目从AAR包工具。不使用任何工具将需要提取到文件并将其添加到他们的混淆器配置。
3.card.io 错误和警告将以 “card.io”作为tag显示在log日志里.
4.如果升级card.io SDK,首先删除所有card.io从库里,捆绑的库会改变

 类似资料: