在您的手机应用程序中扫描信用卡
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);
}
如有疑问请戳这里 東方月初