This Library will help you to implement scan the card(Credit Card, Debit Card) details. It will help you to save your time and mistakes.
1. Add it in your project level build.gradle at the end of repositories:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
2. Add the dependency:
dependencies {
implementation 'com.github.hiteshsarsava:cardscanner:${latestVersion}' //e.g., v0.0.1
}
1. Prepare activity result:
private val resultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
// There are no request codes
val data: Intent = result.data ?: return@registerForActivityResult
val cardDetails: CardDetails =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
data.getSerializableExtra(
ScannerActivity.CARD_DETAILS,
CardDetails::class.java
) as CardDetails
} else {
data.getSerializableExtra(ScannerActivity.CARD_DETAILS) as CardDetails
}
setCardData(cardDetails)
}
}
2. Launch Activity:
resultLauncher.launch(Intent(this@MainActivity, ScannerActivity::class.java))