Skip to content

SoftwareLegends/fingerprint_lib_android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

70 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Android Fingerprint Library πŸ–¨οΈ

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.


✨ Key Features

  • 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.

🎬 Preview

Screenshoot Video
Fingerprint.mp4

πŸš€ Getting Started

1. Include JitPack Repository

In your project's root build.gradle file, add the JitPack repository:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' } 
    }
}

2. Add the Library Dependency

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.


πŸ’» Usage

1. Initialize the Fingerprint Manager

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
    }
}

2. Collect Fingerprint Events

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
        }
    }
}

3. Accessing Captured Images

Note: This is updated in real-time you can use it instead of FingerprintEvent.NewImage event

Retrieve a list of captured images:

val capturedImages: List<ImageBitmap> = fingerprintManager.captures 

4. Initiate Fingerprint Scanning

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 bestCapture and its index with bestCaptureIndex.

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()
}

🀝 Supported Fingerprint Scanners


πŸ—ƒοΈ Sample Application

A sample application showcasing the library's functionalities is available in the app directory.

download the apk


πŸ™Œ Contributing

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.


πŸ“„ License

This project is licensed under the MIT License.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages