Skip to main content

Example: Basic Integration

1. Application.kt

class MyApp : Application() {
override fun onCreate() {
super.onCreate()
MetricFingerprint.init(
context = this,
theme = FingerprintTheme(
companyName = "My Company",
logo = Logo.Url("https://example.com/logo.png"),
color = "#f7cd46"
),
clientKey = "client-key",
secretKey = "secret-key",
environment = Environment.PROD
)
}
}

2. MainActivity.kt

class MainActivity : ComponentActivity() {
private val fingerprintLauncher = registerForActivityResult(
FingerprintAuthContract()
) { result ->
when (result) {
is FingerprintAuthResult.Success -> {
Toast.makeText(
this,
"Verification successful!\nName: ${result.name}\nSUID: ${result.suid}",
Toast.LENGTH_LONG
).show()
}
is FingerprintAuthResult.Error -> {
Toast.makeText(
this,
"Verification failed: ${result.message}",
Toast.LENGTH_SHORT
).show()
}
is FingerprintAuthResult.Cancelled -> {
Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show()
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyAppTheme {
Column {
Button(onClick = {
// Generate token from your API
lifecycleScope.launch {
val token = generateToken()
launchFingerprintAuth(token)
}
}) {
Text("Start Fingerprint Verification")
}
}
}
}
}

private fun launchFingerprintAuth(token: String) {
fingerprintLauncher.launch(FingerprintAuthRequest(token = token))
}

private suspend fun generateToken(): String {
// Call your API to generate verification token
return "your-generated-token"
}
}