card.io无法识别卡

时间:2015-01-30 10:25:45

标签: android card.io

我在我的应用程序中使用了card.io示例代码,但扫描没有捕捉卡片,只关注它。 OnActivityResult没有获取任何数据。什么可以帮忙?使用华硕TF300t。

 public void onScanPress() {
    // This method is set up as an onClick handler in the layout xml
    // e.g. android:onClick="onScanPress"

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

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

    // hides the manual entry button
    // if set, developers should provide their own manual entry mechanism in the app
    scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, false); // default: false

    // matches the theme of your application
    scanIntent.putExtra(CardIOActivity.EXTRA_KEEP_APPLICATION_THEME, true); // default: false

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

和onResult

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

    String resultStr;
    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()
        resultStr = "Card Number: " + scanResult.getRedactedCardNumber() + "\n";

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

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

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

        if (scanResult.postalCode != null) {
            resultStr += "Postal Code: " + scanResult.postalCode + "\n";
        }
    }
    else {
        resultStr = "Scan was canceled.";
    }
   // resultTextView.setText(resultStr);

}

我使用4.0.0 aar,而且我没有提供jniLibs(我想它们必须是.aar)

1 个答案:

答案 0 :(得分:0)

只有在识别出卡片,用户手动输入卡片或用户取消卡片时才会调用onActivityResult。正如@Govtart所解释的那样,并非所有卡都可以识别。请务必先尝试Sample app