Realization of bank card number scanning and identification function by Android
- 2021-10-15 11:23:18
- OfStack
Now, there are many SDK that scan and identify the bank card number, but there are also no charges, but there is a fixed problem, that is, the printed bank card number can't be scanned. I hope which great god will guide the reason to explain. This free SDK is card.io-Android-SDK, githubdi address
The usage method is very simple. For more introduction, please see the GitHub usage documentation:
First import dependencies: compile 'io. card: android-sdk: 5.5. 1'
Then add 1 to the place where you need to call the photo:
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);
Receive the result in 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);
}
}