Android銀行卡掃描獲取銀行卡號(hào)
ard.io開(kāi)源的銀行卡掃描的三方庫(kù)真的是很好用啊。
首先需要在你的module的gradle的依賴文件中添加依賴
compile 'io.card:android-sdk:5.5.1'
2 清單文件中加入如下Activity
<!-- 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" />
<activity android:name="io.card.payment.CardIOActivity" android:configChanges="keyboardHidden|orientation" /> <activity android:name="io.card.payment.DataEntryActivity" />
3 xml文件中
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.dell.scanbankdemo.MainActivity"> <Button android:id="@+id/btn_scan" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="掃描銀行卡" /> <TextView android:id="@+id/tv_card_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="銀行卡號(hào):" /> </LinearLayout>
全部代碼:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public static final int MY_SCAN_REQUEST_CODE = 10;
private Button mScanBtn;
private TextView mNumberTv;//銀行卡號(hào)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mScanBtn = findViewById(R.id.btn_scan);
mScanBtn.setOnClickListener(this);
mNumberTv = findViewById(R.id.tv_card_number);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_scan:
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);
break;
}
}
@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 = "銀行卡號(hào): " + scanResult.getRedactedCardNumber() + "\n"; //只顯示尾號(hào)
resultDisplayStr = "銀行卡號(hào): " + scanResult.getFormattedCardNumber() + "\n"; //顯示銀行卡號(hào)
// Do something with the raw number, e.g.:
// myService.setCardNumber( scanResult.cardNumber );
if (scanResult.isExpiryValid()) {
resultDisplayStr += "有效期:" + 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.";
}
mNumberTv.setText(resultDisplayStr);
// do something with resultDisplayStr, maybe display it in a textView
// resultTextView.setText(resultDisplayStr);
}
}
}
附上github地址
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android Shader應(yīng)用開(kāi)發(fā)之雷達(dá)掃描效果
- Android應(yīng)用中使用ContentProvider掃描本地圖片并顯示
- Android實(shí)現(xiàn)掃描和生成二維碼
- Android實(shí)現(xiàn)掃描二維碼功能
- Android studio 實(shí)現(xiàn)手機(jī)掃描二維碼功能
- Android如何實(shí)現(xiàn)掃描和生成二維碼
- Android實(shí)現(xiàn)銀行卡號(hào)掃描識(shí)別功能
- Android 6.0 掃描不到 Ble 設(shè)備需開(kāi)啟位置權(quán)限的方法
- Android手機(jī)(設(shè)備)連接掃描槍掃碼遇到的問(wèn)題
- Android編程實(shí)現(xiàn)wifi掃描及連接的方法
- Android實(shí)現(xiàn)支付寶AR掃描動(dòng)畫(huà)效果
- Android 二維碼掃描和生成二維碼功能
- Android 開(kāi)機(jī)應(yīng)用掃描相關(guān)總結(jié)
相關(guān)文章
Android+Flutter實(shí)現(xiàn)彩虹圖案的繪制
彩虹,是氣象中的一種光學(xué)現(xiàn)象,當(dāng)太陽(yáng)光照射到半空中的水滴,光線被折射及反射,在天空上形成拱形的七彩光譜。接下來(lái),我們就自己手動(dòng)繪制一下彩虹圖案吧2022-11-11
Android選擇與上傳圖片之PictureSelector教程
這篇文章主要介紹了在Android中對(duì)于圖片的選擇與上傳方法,本文介紹了PictureSelector的相關(guān)使用教程,學(xué)習(xí)Android的同學(xué)進(jìn)來(lái)看看吧2021-08-08
Android基于socket實(shí)現(xiàn)的簡(jiǎn)單C/S聊天通信功能
這篇文章主要介紹了Android基于socket實(shí)現(xiàn)的簡(jiǎn)單C/S聊天通信功能,結(jié)合實(shí)例形式分析了Android使用socket實(shí)現(xiàn)客服端與服務(wù)器端數(shù)據(jù)的發(fā)送與接收處理技巧,需要的朋友可以參考下2016-10-10
Android Studio綁定下拉框數(shù)據(jù)詳解
這篇文章主要為大家詳細(xì)介紹了Android Studio綁定下拉框數(shù)據(jù),Android Studio綁定網(wǎng)絡(luò)JSON數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
詳解Android使用Handler造成內(nèi)存泄露的分析及解決方法
這篇文章主要介紹了詳解Android使用Handler造成內(nèi)存泄露的分析及解決方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12

