This library provides a simple and efficient way to integrate fingerprint scanners into your Android applications. It offers support for various fingerprint scanner models and streamlines the process of capturing and processing fingerprint images.
- Effortless Integration: Get started quickly with a simple setup.
- Real-time Feedback: Respond to fingerprint events such as device connection, capture success, and errors.
- Image Handling: Conveniently access and use captured fingerprint images.
- Multiple Scanner Support: Works with fingerprint scanners from different manufacturers including HF Security and Futronic.
| Screenshoot | Video |
|---|---|
|
Fingerprint.mp4 |
In your project's root build.gradle file, add the JitPack repository:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}Include the library in your module-level build.gradle:
dependencies {
implementation("com.github.SoftwareLegends:fingerprint_lib_android:<LATEST_VERSION>")
}Replace <LATEST_VERSION> with the latest version from the badge at the top of this README.
Initialize the fingerprint manager within your activity or fragment:
import com.fingerprint.FingerprintInitializer
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
val fingerprintManager = FingerprintInitializer(
context = this,
lifecycle = lifecycle,
scope = CoroutineScope(Dispatchers.IO)
).create()
// ... Use fingerprintManager
}
}Use a Flow to collect and respond to fingerprint events:
lifecycleScope.launch {
fingerprintManager.eventsFlow.collect { event ->
when (event) {
FingerprintEvent.CapturingFailed -> { /* Handle capture failure */ }
FingerprintEvent.Connected -> { /* Handle successful connection */ }
FingerprintEvent.ConnectingFailed -> { /* Handle connection failure */ }
// ... Handle other events
is FingerprintEvent.NewImage -> {
val bitmap = event.bitmapArray // Access the captured fingerprint image
// ... Do something with the bitmap
}
}
}
}Alternatively, you can use collectAsState() within Compose:
val event = fingerprintManager.eventsFlow.collectAsState()
LaunchedEffect(key1 = event) {
println(event.message)
when (event) {
FingerprintEvent.CapturingFailed -> { /* Handle capture failure */ }
FingerprintEvent.Connected -> { /* Handle successful connection */ }
FingerprintEvent.ConnectingFailed -> { /* Handle connection failure */ }
// ... Handle other events
is FingerprintEvent.NewImage -> {
val bitmap = event.bitmapArray // Access the captured fingerprint image
// ... Do something with the bitmap
}
}
}Note: This is updated in real-time you can use it instead of
FingerprintEvent.NewImageevent
Retrieve a list of captured images:
val capturedImages: List<ImageBitmap> = fingerprintManager.captures Use the scan() method to start capturing fingerprints:
val isScanning = fingerprintManager.scan(count = 5) // 'count' is the number of desired captures
if (isScanning.not()) {
Toast.makeText(context, event.message, Toast.LENGTH_SHORT).show()
}Important Notes:
- The connection and disconnection lifecycle are automatically handled, simplifying your code.
- Access the best quality capture image with
bestCaptureand its index withbestCaptureIndex.
The FingerprintManager interface exposes convenient methods and properties for seamless integration:
interface FingerprintManager : DefaultLifecycleObserver {
val eventsFlow: SharedFlow<FingerprintEvent>
val captures: List<ImageBitmap>
val bestCapture: ImageBitmap?
val bestCaptureIndex: Int
val deviceInfo: FingerprintDeviceInfo
val progress: Float
val isConnected: Boolean
val isScanning: Boolean
fun reset()
fun connect()
fun disconnect()
fun scan(count: Int): Boolean
fun improveTheBestCapture(isApplyFilters: Boolean = false, isBlue: Boolean = false)
override fun onResume(owner: LifecycleOwner) = connect()
override fun onStop(owner: LifecycleOwner) = disconnect()
}- HF Security
- HF4000
(Tested and verified)β - Other models may also be compatible.
- HF4000
- Futronic
- FS80H
(Tested and verified)β
- FS80H
A sample application showcasing the library's functionalities is available in the app directory.
Contributions are always welcome! If you find any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
