在您的手機應用程序中掃描信用卡

card.io官網

1.添加依賴

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

2.簡單布局

 <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="scan"
        android:text="掃描銀行卡" />

    <TextView
        android:id="@+id/tv_num"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="請點擊掃描銀行卡進行卡號掃描!" />

3.代碼設置

點擊觸發掃描

    public void scan(View view) {
        Intent intent = new Intent(this, CardIOActivity.class)
                .putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, false)
                .putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false)
                .putExtra(CardIOActivity.EXTRA_HIDE_CARDIO_LOGO, true)//去除水印
                .putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, true)//去除鍵盤
                .putExtra(CardIOActivity.EXTRA_LANGUAGE_OR_LOCALE, "zh-Hans")//設置提示為中文
                .putExtra("debug_autoAcceptResult", true);
        startActivityForResult(intent, REQUEST_AUTOTEST);
    }

掃描完成回調

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String outStr = new String();
        if ((requestCode == REQUEST_AUTOTEST) && data != null
                && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
            CreditCard result = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);
            if (result != null) {
                outStr += "Card number: " + result.cardNumber + "\n";
            }
        }
        tv_num.setText(outStr);
    }

Demo源碼歡迎start

如有疑問請戳這裏 東方月初

分享