Android銀行卡掃描獲取銀行卡號
更新時間:2018年09月06日 11:35:46 作者:零下十五度w
這篇文章主要為大家詳細介紹了Android銀行卡掃描獲取銀行卡號的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
ard.io開源的銀行卡掃描的三方庫真的是很好用啊。
首先需要在你的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="銀行卡號:" /> </LinearLayout>
全部代碼:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public static final int MY_SCAN_REQUEST_CODE = 10;
private Button mScanBtn;
private TextView mNumberTv;//銀行卡號
@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 = "銀行卡號: " + scanResult.getRedactedCardNumber() + "\n"; //只顯示尾號
resultDisplayStr = "銀行卡號: " + scanResult.getFormattedCardNumber() + "\n"; //顯示銀行卡號
// 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地址
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Android Shader應用開發(fā)之雷達掃描效果
- Android應用中使用ContentProvider掃描本地圖片并顯示
- Android實現(xiàn)掃描和生成二維碼
- Android實現(xiàn)掃描二維碼功能
- Android studio 實現(xiàn)手機掃描二維碼功能
- Android如何實現(xiàn)掃描和生成二維碼
- Android實現(xiàn)銀行卡號掃描識別功能
- Android 6.0 掃描不到 Ble 設備需開啟位置權限的方法
- Android手機(設備)連接掃描槍掃碼遇到的問題
- Android編程實現(xiàn)wifi掃描及連接的方法
- Android實現(xiàn)支付寶AR掃描動畫效果
- Android 二維碼掃描和生成二維碼功能
- Android 開機應用掃描相關總結
相關文章
Android OnFocuChangeListener焦點事件詳解
這篇文章主要為大家詳細介紹了Android OnFocuChangeListener焦點事件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09
Android ViewPager實現(xiàn)無限循環(huán)輪播廣告位Banner效果
這篇文章主要為大家詳細介紹了Android ViewPager實現(xiàn)無限循環(huán)輪播廣告位Banner效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07
淺談 Android 7.0 多窗口分屏模式的實現(xiàn)
這篇文章主要介紹了淺談 Android 7.0 多窗口分屏模式的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-03-03

