This is an Android project allowing you to use the advanced biometric authorization features.

Overview

Buy Me A Coffee

PLEASE NOTE:

If your project has minSDK 23 and should support only basic Fingerprint Authorization on most devices - take a look first at the AndroidX's Biometric .

If you still need advanced Biometric authentication use Fingerpint, Face or Iris on the wide range of devices - see doc below.

Advanced BiometricPromptCompat

Introduction

What is BiometricPrompt API?

This is a new API that declares that the system takes care of a unified way to use different biometric identification methods - fingerprint, face, iris, etc., as well as a unified way to display the UI on all devices.

To learn more, read BiometricPrompt Reference in Android Developers site.

Unfortunately, this simplification hides a number of problems.

  • On Android 9, there is no way to simply get information about whether there is available biometric hardware and whether biometric data is enrolled. Android 10 provides BiometricManager that partially solves this problem.
  • Some manufacturers have removed/do not display the biometric UI
  • Biometric Auth solutions like Samsung Pass SDK or Meizu Fingerprint need to implement separately
  • No way to identify what types of biometric auth available on the device.

How to use BiometricPromptCompat in old devices?

BiometricPromptCompat is designed to be compatible with the largest number of Android devices.
Its interface is very close to the original BiometricPrompt.
Minimal supported SDK - Android 4.1 JellyBean (API 16)

Key features

  • Unified UI for all devices - starts from Android 4.1 and to Android 11
  • Contains fix for devices WITHOUT system BiometricPrompt UI (like LG G8 or OnePlus 6T)
  • Dark/Light themes supported; Also you able to get the background color of the current Biometric dialog
  • Auth in Split-Screen Mode supported
  • Wide range of supported biometrics

Supported types of biometric authentication

Type Details Tested on
BiometricPrompt API Android 9+ Xiaomi POCO F1
Samsung IrisID Android 7+ and Samsung devices Samsung Galaxy S10 (confirmation required)
Samsung Pass Fingerprint Android 4.4-6.0 and Samsung devices Samsung Galaxy S5
Fingerprint Android 6+ Xiaomi POCO F1
In-screen Fingerprint Android 8+ OnePlus 6T/OnePlus 7 Pro
Meizu Fingerprint Android 5.0-5.1 and Meizu devices Meizu Pro 5
Face Unlock (aka Trusted Faces) Android 4.1+ Prestigio PAP3400
Huawei FaceID Android 8+ and Huawei devices Huawei MatePad T8, Huawei P30
Huawei 3D FaceID Android 10+ and Huawei devices Huawei Mate 30 Pro (confirmation required)
Xiomi FaceUnlock Android 7+ and Xiaomi devices Xiaomi POCO F1
Samsung FaceID Android 7+ and Samsung devices Samsung Galaxy S10 (confirmation required)
Oppo FaceID Android 8+ and Oppo devices Not tested yet
Vivo FaceId Android 8+ and Vivo devices Not tested yet

Screenshots:

Xiaomi Pocophone F1

Pocophone F1

Samsung Galaxy S5

Samsung Galaxy S5

Huawei Mate P40 Pro

Huawei Mate P40 Pro

Prestigio PAP3400

Prestigio PAP3400

Video from Xiaomi Pocophone F1
Watch the video

Setup

VERSION = Maven Central

Add dependency to Gradle

dependencies {
 implementation 'dev.skomlach:biometric:${VERSION}' 
}

Usage

BiometricPromptCompat API

At first, better in Application.onCreate(), call

BiometricPromptCompat.init(callback);//Callback - null or Runnable{ do_something_after_init(); }     

BiometricManagerCompat

static boolean hasEnrolled() - returns true if specified biometric enrolled

static boolean isBiometricSensorPermanentlyLocked() - returns true if specified biometric permanently locked; Device lock-unlock or reboot required from the user

static boolean isHardwareDetected() - returns true if specified biometric hardware available

static boolean isLockOut() - returns true if specified biometric temporarily locked; Usually need to wait for 30 seconds and the system will reset this lock

static boolean isNewBiometricApi() - returns true if BiometricPrompt API used for specified biometric

static boolean openSettings(Activity) - returns true if open the "Enroll biometric" settings screen for specified biometric

static boolean isBiometricEnrollChanged - returns true if enrollment changed for specified biometric.

NOTE!!! Be careful using 'isBiometricEnrollChanged' - due to technical limitations, it can return incorrect result in some cases

BiometricAuthRequest

Allows you to configure the type of target biometrics.
It can be any combination of BiometricApi and BiometricType;
Default is BiometricAuthRequest(BiometricApi.AUTO, BiometricType.BIOMETRIC_ANY, BiometricConfirmation.ANY) - means any available BiometricApi and BiometricType

BiometricConfirmation:

BiometricConfirmation.ANY - any biometric confirm the user

BiometricConfirmation.ALL - all (one-by-one) biometrics confirm the user

BiometricApi:

BiometricApi.AUTO - the library will peek at the best-matched API

BiometricApi.LEGACY_API - forced usage of legacy biometric APIs like Fingerprint or FaceUnlock, and custom UI

BiometricApi.BIOMETRIC_API - forced usage of new BiometricPrompt API

BiometricType:

BiometricType.BIOMETRIC_FINGERPRINT - Use only Fingerprint biometric, ignore others

BiometricType.BIOMETRIC_FACE - Use only FaceId biometric, ignore others

BiometricType.BIOMETRIC_IRIS - Use only Iris biometric, ignore others

BiometricType.BIOMETRIC_ANY - use any available biometric (multiple types supported)

BiometricPromptCompat.Builder

BiometricPromptCompat.Builder builder =  
 new BiometricPromptCompat.Builder(getActivity()) .setTitle("Biometric demo") .setNegativeButton("Cancel", null); BiometricPromptCompat biometricPromptCompat = builder.build();    

Please note:
Methods builder.setTitle() and builder.setNegativeButton() are mandatory.

BiometricPromptCompat:

void authenticate(BiometricPromptCompat.Result resultCallback) - start biometric auth workflow

void cancelAuthenticate() - cancel active biometric auth workflow

boolean cancelAuthenticateBecauseOnPause() - Useful if you need to allow biometric auth in Split-Screen mode; Recommended to call this method in onPause() and use returned value to avoid biometric auth restart.
Returns false and keep biometric auth on display if the app in Split-Screen mode, returns true and cancel active biometric auth otherwise

@ColorRes int getDialogMainColor() - returns dialog background color

BiometricPromptCompat.Result

void onSucceeded(Set<BiometricType> confirmed) - User successfully authenticated

void onCanceled() - Biometric authentication was canceled

void onFailed(AuthenticationFailureReason reason) - Error happens, see details in AuthenticationFailureReason

void onUIOpened()/void onUIClosed - Biometric UI on display or closed

False-positive and/or False-negative detection

On pure API28 implementation (built-in BiometricPrompt API) is no way to get 'isBiometricEnrolled' results for specific biometric, like Iris/Face, etc. So, some tricks have used that try to determine by indirect signs which biometric data are used (like "if NOT fingerprint, BUT something enrolled in the System Settings").

There are edge cases where we cannot tell exactly what type of biometrics is enrolled - for example, if it is Samsung with Face and Iris - in this case, the code can give a incorrect result. It can happen if you set BiometricApi.BIOMETRIC_API + BiometricType.BIOMETRIC_FACE or BiometricApi.BIOMETRIC_API + BiometricType.BIOMETRIC_IRIS

Fortunately, for Samsung with Face and Iris, the 'legacy' check should work correctly, so for general cases when you use BiometricApi.AUTO/LEGACY_API + BiometricType.BIOMETRIC_FACE/BIOMETRIC_IRIS all should work fine.

I have a device that can be unlocked using Fingerprint/Face/Iris and(or) I can use this biometric type in pre-installed apps. But it doesn't work on 3rd party apps. Can you help?

Yes, this is, unfortunately, happening very often. Many functions demanded by the market are often implemented by device manufacturers before the same API appears in the official Android SDK.

The device manufacturer has implemented biometric authentication via fingerprint/face/iris, but "forgot" to provide access to this implementation for third-party developers. Therefore, preinstalled (system) applications developed by the device manufacturer can use biometrics, while banking applications, password managers, and other third-party applications cannot.

And unfortunately, sometimes manufacturers create such implementations that it is impossible to access using any known technic.

Anyway, research and testing required for each case, so feel free to create issues or contact directly with me.

Types of Biometrics

https://www.biometricsinstitute.org/what-is-biometrics/types-of-biometrics/

HOWTO SETUP

FaceUnlock: https://www.xda-developers.com/face-unlock/

Fingerprint: https://www.wikihow.com/Set-Up-the-Fingerprint-Scanner-on-an-Android-Device

IrisUnlock: https://www.samsung.com/ph/support/mobile-devices/what-is-iris-scanning-and-how-to-use-it-on-my-samsung-galaxy-device/

Contact author

Telegram: @SergeyKomlach

Twitter: @SergejKomlach

License

Apache License 2.0

Comments
  • One Plus 9 fingerprint unlock calls onSucceeded when dialog is cancelled

    One Plus 9 fingerprint unlock calls onSucceeded when dialog is cancelled

    When testing the library on the One Plus 9 I have noticed that if I cancel the dialog while prompting for a fingerprint, instead of getting an onCanceled callback like I do on other devices I am seeing an onSucceeded callback. This is allowing users to bypass the security lock simply by cancelling the dialog.

    There appears to be no difference in the onSucceeded callback on this device if I do actually authenticate with my fingerprint as the return parameter is identical.

    bug 
    opened by jamiehiggins 15
  • Bug: face authentication dialog out of screen bounds in portrait layout for tablet device

    Bug: face authentication dialog out of screen bounds in portrait layout for tablet device

    Device: samsung galaxy tab s7 Android version: 12 When using face authentication dialog in portrait layout for tablet device it goes out of screen bounds (i.e. too wide).

    Specifications:

    Face authentication dialog in landscape layout:

    Face authentication dialog in portrait layout:

    opened by sandboiii 6
  • LEGACY_API BIOMETRIC_FACE Prompt not closing correctly

    LEGACY_API BIOMETRIC_FACE Prompt not closing correctly

    On the Test app after closing the LEGACY_API/BIOMETRIC_FACE Prompt by tapping the upper empty space outside the prompt box, the prompt will keep on the screen forever. A strange empty prompt will show up by changing orientation or back from background.

    bug 
    opened by MakTszHim 4
  • Failed to resolve

    Failed to resolve

    Failed to resolve: com.microsoft.device.dualscreen:fragmentshandler:1.0.0-alpha02 Failed to resolve: com.tencent.soter:soter-core:+ Failed to resolve: com.microsoft.device.dualscreen:core:1.0.0-alpha01

    opened by TolikB 4
  • One Plus 9 fingerprint unlock (Not fixed)

    One Plus 9 fingerprint unlock (Not fixed)

    Unfortunately #305 does not appear to be fixed when I'm importing the new version of the library.

    I've dived into the code to try and work out why it was working on your APK build and the difference is as follows:

    I believe you sent me a debug build and because of this the isExperimentalFeaturesEnabled flag was set to true.

    This results in the following code being executed (in BiometricPrompApi28Impl):

                if (builder.isExperimentalFeaturesEnabled() && builder.getPrimaryAvailableTypes().size == 1 && builder.getPrimaryAvailableTypes()
                        .toMutableList()[0] == BiometricType.BIOMETRIC_FINGERPRINT
                ) {
                    forceToFingerprint = true
                }
    

    and the forceToFingerprint is set to true.

    I am able to get it working by setting the experimental features to true when I'm calling.

    opened by jamiehiggins 3
  • Check false-positive results for some configurations

    Check false-positive results for some configurations

    Original question - https://github.com/Salat-Cx65/AdvancedBiometricPromptCompat/issues/105 I confirm that issue reproduced on Poco F1+ BiometricApi.BIOMETRIC_API + BiometricType.BIOMETRIC_FACE

    bug 
    opened by sergeykomlach 3
  • What do you mean? Our team is concerned now

    What do you mean? Our team is concerned now

    https://github.com/Salat-Cx65/AdvancedBiometricPromptCompat/blob/fa9036476aa6e6ef626fbc1d47f8b9a76b379eba/biometric/src/main/java/dev/skomlach/biometric/compat/utils/hardware/Android28Hardware.kt#L268

    question 
    opened by tieorange 3
  • android:attr/lStar not found

    android:attr/lStar not found

    I'm using dev.skomlach:biometric:2.0.90, minSDKVersion 21, target SDK 29, compile SDK 29, and kotlin version 1.5. I'm getting error AAPT: error: resource android:attr/lStar not found.

    opened by knifemaster7 2
  • i went show popup biometric dialog

    i went show popup biometric dialog

    val biometricPromptCompat = BiometricPromptCompat.Builder(BiometricAuthRequest(BiometricApi.AUTO, BiometricType.BIOMETRIC_ANY, BiometricConfirmation.ALL), this) .setTitle("Biometric demo") .setSubtitle("Test by gus") .setDescription("Biometric Description: BlaBlablabla Some very long text BlaBlablabla and more text and more and more and more") .setNegativeButton("Cancel", null) .build()

    //not show popup biometric dialog

    opened by sarayut8 1
  • Glitches with Notifications

    Glitches with Notifications

    Some weird bugs happens with Notifications.

    • notifications not dismissed automatically
    • notifications background color not changed on Android 12
    • to many notifications on some devices like Samsung
    opened by sergeykomlach 1
  • Incorrect (unclear for end user) behavior for BiometricConfirmation.ALL  on Samsung devices

    Incorrect (unclear for end user) behavior for BiometricConfirmation.ALL on Samsung devices

    When set BiometricConfirmation.ALL, on Samsung devices where exists one biometric chooser, happens "biometric re-ask" workflow. Technically, it happens because of one 'biometric' (BiometricPrompt API) executed, but the library detects few methods, so the next one was asked (with custom UI). Confusion happens cause of 'fingerprint' icon appears + one (system) dialog closed and second one (custom) appears

    enhancement 
    opened by sergeykomlach 1
  • Incorrect behavior of face authentication on Honor Play device

    Incorrect behavior of face authentication on Honor Play device

    Device: Honor Play Android version: 9 There are problems with face authentication on Honor Play. The dialog displays text about fingerprint scanner even though biometric type is BIOMETRIC_FACE and authentication not working on this device.

    Video:

    https://user-images.githubusercontent.com/17468894/168077078-d8ac97fe-aa5e-4dd0-a1bb-af788b911660.mp4

    Logs:

    log1.txt log2.txt

    opened by sandboiii 18
Owner
Sergej Komlach
Sergej Komlach
An Android app that gives you a password generated by a given phrase with a custom algorithm, it also has password and biometric security.

An Android app that gives you a password generated by a given phrase with a custom algorithm, it also has password and biometric security.

Marcos Ariel Paccor 1 May 23, 2022
Fingerprint Biometric Authentication Android

Fingerprint-BiometricAuthentication-Android Preview Authentication Succeeded Aut

mohamed tamer 4 Apr 12, 2022
Project allowing to query products (languages, libraries, databases, etc) by their properties.

Products app This project allow to search products (mostly software products for now such as languages, libraries etc) based on their properties. For

null 1 May 1, 2022
Android News App built in kotlin with implementation of MVVM architecture, android navigation components and retrofit. Displays news to users allowing them to share and save news.

News-App Android news app built in kotlin that fetches news data from news api with Retrofit and displays news to users. This App follow MVVM architec

Raj Manjrekar 16 Dec 29, 2022
Android application allowing to sniff and inject Zigbee, Mosart and Enhanced ShockBurst packets on a Samsung Galaxy S20

This Android application allows to sniff and inject Zigbee, Mosart and Enhanced ShockBurst packets from a Samsung Galaxy S20 smartphone. It interacts with a set of patches installed on the phone Bluetooth controller, allowing to add new capabilities to communicate using the previously mentioned protocols.

Romain Cayre 52 Nov 1, 2022
Asteroid radar app -Second Project from Udacity Advanced Android Development Kotlin Nanodegree

Asteroid radar app Using open-source Nasa Api Asteroid Radar is an app to view the asteroids detected by NASA that pass near Earth, you can view all t

Mostafa Mohamed 2 Aug 29, 2022
A general purpose kotlin library that use kotlin coroutines, flows and channels to provide timer features with the most easy and efficient way

Timer Timer is a general purpose kotlin library that use kotlin coroutines, flows and channels to provide timer features with the most easy and effici

Amr Saraya 3 Jul 11, 2022
Samples demonstrating the features and use of Koala Plot, a Compose Multiplatform based charting and plotting library written in Kotlin.

Koala Plot Samples This repository houses samples demonstrating the use and features of Koala Plot libraries. How to run Build koalaplot-core with the

Koala Plot 6 Oct 18, 2022
A sample Android app which showcases advanced usage of Dagger among other open source libraries.

U+2020 A sample Android app which showcases advanced usage of Dagger among other open source libraries. Watch the corresponding talk or view the slide

Jake Wharton 5.7k Dec 27, 2022
An advanced DEX editor for Android.

An advanced DEX editor for Android.

Mike Anderson 75 Jan 3, 2023
Android app with advanced usage of Epoxy library

Epoxy Advanced Best practices and advanced usages (EditText & Forms) of Epoxy library written in accordance with the Modular and Clean Architectures.

Yusuf Gökmen Arısoy 6 Aug 30, 2022
An advanced Kotlin (Android Native) application that uses SOLID architectural principles, consumes a RESTFUL Service, downloads & images using best practices

Dog-Playground Kotlin An advanced Kotlin (Android Native) application that uses SOLID architectural principles, consumes a RESTFUL Service, downloads

Amose Suwali 1 Jan 10, 2022
Advanced Android Weather App using MVVM Architecture Sample (ViewModel + LiveData + Kotlin + volley) = Weather App

Advanced Android Weather App using MVVM Architecture Sample (ViewModel + LiveData + Kotlin + volley) = Weather App Video Weather.-.HD.720p.mov Introdu

wykee2 4 Jul 12, 2022
NetGuard provides simple and advanced ways to block access to the internet

NetGuard NetGuard provides simple and advanced ways to block access to the internet - no root required. Applications and addresses can individually be

Marcel Bokhorst 598 Dec 31, 2022
LirandAPI - Advanced Kotlin API for Spigot

Lirand API Lirand API allows you to develop Spigot plugins faster, easier and mo

dyamo 9 Dec 4, 2022
Pixel Launcher Mods a root app for Android 12+ that enables you to add a number of features to the stock Pixel Launcher

A root app that enables you to add a number of features to the stock Pixel Launcher, without needing Xposed

Kieron Quinn 430 Jan 2, 2023
when you use restful api and network get disconnect you have to store your data local for make your app faster and work on ofline mode

AppArchitectureOflineMode when you use restful api and network get disconnect you have to store your data local for make your app faster and work on o

Kareem-Mansy 3 Jun 20, 2021
Shot is an Android project you can use to write screenshot for your apps in a simple and friendly way

Shot is an Android project you can use to write screenshot for your apps in a simple and friendly way. What is this? Shot is a Gradle plugin and

Pedro Gómez 1k Dec 30, 2022
Android app that helps you keep track of the medical supplements you need to take and how you spend your days

Android app that helps you keep track of the medical supplements you need to take and how you spend your days, similar to a bullet journal. It also allows you to reflect on your day, week, year, etc.

Rachelle Hu 4 Nov 10, 2022