Links

Android 🤖

Our CardScanView Kotlin Activity makes it easy to add insurance card scanning to any Android application in 5 minutes or less.
The Android/Kotlin library is currently in Beta, please let us know if you find any issues.
[IMG/GIF]

Requirements

  • Android API level 21 or higher
  • AndroidX compatibility
  • Kotlin coroutine compatibility

Installation

The library is published in the maven central repository, so installation is as simple as adding the dependency to your build.gradle
dependencies {
implementation 'ai.cardscan:insurance-cardscan:0.2.8'
}

Usage

Import the library into your project files:
import ai.cardscan.insurance.CardScanActivityResultHandler
import ai.cardscan.insurance.CardScanActivityResult
import ai.cardscan.insurance.CardError
import ai.cardscan.insurance.CardScanActivity

Basic Example:

import ai.cardscan.insurance.CardScanActivityResultHandler
import ai.cardscan.insurance.CardScanActivityResult
import ai.cardscan.insurance.CardError
import ai.cardscan.insurance.CardScanActivity
​
class OnboardingActivity : AppCompatActivity(), CardScanActivityResultHandler {
​
lateinit var cardScanResultLauncher : ActivityResultLauncher<Intent>
​
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_onboarding)
​
​
cardScanResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
//use CardScanActivity for processing results and call the success/error/canceled callbacks.
CardScanActivity.processResult(this@MainActivity, result)
}
​
findViewById<View>(R.id.scanCardButton).setOnClickListener { _ ->
getSession { session ->
//trigger the loading of CardScanActivity with user's session token
CardScanActivity.start(
activity = this,
resultLauncher = cardScanResultLauncher,
sessionToken = session,
live = false
)
}
​
}
}
​
private fun getSession(callback: (session: String) -> Unit) {
//get the user's sessions by calling your server endpoints.
//See Authentication for more details.
val httpAsync = "https://{{YOUR_SERVER_BASE_URL}}/cardscan-session"
.httpPost()
.responseJson { _, _, result ->
//check for errors :)
val jsonObject = result.get().obj()
val session = jsonObject["session"] as String
callback(session)
}
}
​
override fun scanSuccess(card: CardScanActivityResult) {
Log.d("CardScan", "ScanSuccess $card")
}
override fun scanCanceled() {
Log.d("CardScan", "scanCanceled")
}
​
override fun scanError(error: CardError) {
Log.d("CardScan", "scanError $error")
}
​
}
​

​