I am trying to add fingerPrint authentication in my application with the use of BioMetricPrompt of API level 29.
I follow some code for that but most of the available codes are for the lower-level API. In API 29, BiometricPrompt class has big changes in compare of lowe level API.
My main query is how to initialize BiometricPrompt class for the project where targeted API is API 28 or 29.
I am trying to do it with FingerprintManagerCompat but it is deprecated now. So, please help me with create instance of BiometricPrompt class.
After I did not get any feedback and research of almost 24 hours I get a solution for my problems after research on different resources.
So, androidx.core.hardware.fingerprint.FingerprintManagerCompat
is deprecated in newly available API 28 and 29 and instead of this, there is another class available that is androidx.biometric.BiometricPrompt
.
This new BiometricPrompt is more efficient and helping for displaying a standard dialog to guide the user through the authentication process, performing the authentication and reporting the results to the app. The BiometricPrompt class has a static builder class PromptInfo
that can be used to configure and create BiometricPrompt instances.
So, the solution is for creating an instance of BioMetricPrompt as per newly available API is:
val biometricPrompt = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric Demo")
.setSubtitle("Authentication is required to continue")
.setDescription("This app uses biometric authentication to protect your data.")
.setNegativeButtonText("Cancel")
.build()
BiometricPrompt(this.activity!!, getMainExecutor(this.activity), getAuthenticationCallback()).authenticate(biometricPrompt)