Android 🤖
Our CardScanActivity
Kotlin Activity makes it easy to add insurance card scanning to any Android application in 5 minutes or less.
Requirements
Android API level 23 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
Usage
Import the necessary classes from the library into your activity or fragment:
Basic usage Example:
Available Properties
When launchingCardScanActivity
, a CardScanConfig
instance should be passed with properties for server connection and UI customization.
Main Config Props
live
false
Boolean
Toggle the production or sandbox version. Default: false
sessionToken
true
String
backsideSupport
false
Boolean
Enable scanning of the front and back side of the card. Default: false
eligibility
false
EligibilityRequest
Send an EligibilityRequest object with the properties shown above to perform an eligibility check.
UI/UX Customization Props
The card scanner view is designed to be customizable. Please see the Customization ⚙️ section of UI Components to adjust these elements to match your application's branding and theme:
Note: All UI/UX Props are optional
messages
Object
Customize the text displayed by the UI.
messageFontSize
Float
Set the size of the text displayed by the UI.
messageTextColor
Int
Set the color of the text displayed by the UI.
messageBackgroundColor
Int
Set the background color of the text displayed by the UI.
autoSwitchActiveColor
Int
Set the color of the auto scan switch.
autoSwitchInactiveColor
Int
Set the color of the disabled auto scan switch.
progressBarColor
Int
Set the color of the progress bars or bounding box that surrounds the card scanning area.
widgetBackgroundColor
Int
Set the main background color for the widget.
Cardscan activity launcher props
activity
Activity
The activity from which the CardScan activity will be started. Usually MainActivity
properties
CardScanConfig
Object to set the parameters for the scanner
closeAfterSuccess
Boolean
Whether to automatically finish Cardscan activity after successful scan.
closeAfterSuccessDelay
Long
Time in milliseconds to wait before finishing Cardscan activity, after a successful scan.
closeAfterErrorDelay
Long
Time in milliseconds to wait before finishing Cardscan activity, after an error was thrown.
onSuccess Callback
onSuccess
triggers when card scanning process completes successfully. This function receives the scanned card data as an argument.
Usage
To use the onSuccess
callback, pass a function that receives the scanned card data to the onSuccess function in CardScanHelper:
In this example, the handleCardScanSuccess
function logs the scanned card data to the console when the scanning process is completed successfully and your MainActivity or fragment resumes.
onError Callback
onError
triggers after a failure occurs during the card scanning process. This function receives an error object as an argument.
Usage
Pass a function that receives the error object or implement your callback directly inside the helper:
In this example, the handleCardScanError
logs the error object when a scanning failure occurs.
By using the onSuccess
and onError
callbacks, you can handle successful and failed scanning event with custom actions or display appropriate messages to the user.
onCancel and onRetry Callbacks
onCancel
expects a function that will trigger after users cancel the card scanning process. This could be useful for tracking user behavior or displaying an appropriate message. onRetry
expects a function that will trigger when your activity or fragment resumes, if the user had a retry of a scanning process.
onEligibilitySuccess and onEligibilityError Callbacks
Both callbacks expect a function that will trigger in either case. onElibiligitySuccess
callback will pass an Eligibility
object and onEligibilityError
will pas an EligibilityError
object. Expect the same behavior as the other callbacks, this objects will be passed once your activity or fragment resumes.
Camera Permissions 📸
Our SDK requires camera access to scan insurance cards. While the CardScan widget automatically requests camera permissions during widget load, it does not present any UI for handling permissions or manage permission failures, particularly on mobile devices.
Requirement: We require that developers handle camera permission requests before loading the CardScan widget. This will allow you to manage the permission flow consistently within your application, providing custom error handling and user feedback if permission is denied.
Recommendation: We recommend following best practices when requesting camera permissions:
Pre-flight the request:
Within your app, prompt the user with a clear explanation of why camera access is needed and ask for confirmation (Yes/No). This improves transparency, builds trust, and can reduce the likelihood of the user denying the request.
Handle permission rejection gracefully:
Soft rejection (user-level): If the user declines the camera access within your app, provide a helpful message that explains the impact of this choice and give them the option to reconsider later.
Hard rejection (system-level): In case the user has previously denied the camera permission at the system level, guide them to the device settings where they can manually enable the camera access. Display an appropriate message explaining how to do this and the importance of enabling the permission for the app's functionality.
For Android applications, we recommend taking a dive into the official docs: https://developer.android.com/training/permissions/requesting
Suggestion for code to include with Cardscan launcher:
Last updated