Skip to content

Commit 45977cb

Browse files
Adding readme.
1 parent 9e468b6 commit 45977cb

File tree

5 files changed

+165
-11
lines changed

5 files changed

+165
-11
lines changed

.github/Dialog.png

158 KB
Loading

.github/auth_failed.gif

464 KB
Loading

.github/auth_success.gif

243 KB
Loading

README.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,165 @@
44

55
#### FingerprintDialog from Android 28 (P) back ported to Android 23 (M).
66

7+
## Why do we need this library⁉️
8+
- Fingerprint is currently the most secure and most user friendly way of authenticating the user in Android.
9+
- Android provides different APIs to deal with the fingerprint authentication. These APIs changed overtime.
10+
- Android versions below API 23 did not support fingerprint hardware at all.
11+
- Android versions between API 23 and API 27, uses [`FingerprintManager`](https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html) for fingerprint authentication. Developer has to manually authenticate by implementing bunch of APIs.
12+
- Android version above API 28, uses [`FingerprintDialog`](https://developer.android.com/reference/android/hardware/fingerprint/FingerprintDialog.html) for fingerprint authentication.
13+
- Due to the Android fragmentation developer has to implement all those APIs based on the android version.😔 It makes managing fingerprint authentication very hard.
14+
- This library aims to simplify fingerprint authentication by providing backport of the `FingerprintDialog` from Android P and provides single public APIs for the authentication all the way to API 14. So as a developer you don't have to deal with the complexity of dealing with different APIs.✌️
15+
16+
## Features:
17+
- Extremely lightweight 🏋.
18+
- Backport of [`FingerprintDialog`](https://developer.android.com/reference/android/hardware/fingerprint/FingerprintDialog.html) from Android P, provides same fingerprint authentication on all Android versions.
19+
- Easy to integrate. All you have to do is implement the builder and you are done. The library will take care of authentication based on the device's android version.
20+
- Classifies different error codes provided by the Android framework and wraps them into different error callbacks for easy error handling.
21+
22+
## How to use this library?
23+
- ### Gradle dependency:
24+
- Add below dependency into your build.gradle file.
25+
```groovy
26+
implementation 'com.kevalpatel2106:fingerprint-dialog-compat:1.0'
27+
```
28+
- For other build systems see [Import.md](/.github/IMPORT.md).
29+
30+
- ### Prepare the builder.
31+
- Create the `FingerprintDialogBuilder` and provide the title, subtitle and the description. Application should explain why they need to access user's fingerprint.
32+
- ![Dialog](.github/Dialog.png)
33+
34+
#### Java:
35+
```java
36+
final FingerprintDialogBuilder dialogBuilder = new FingerprintDialogBuilder(Activity.this)
37+
.setTitle(/* Title of the fingerprint dialog */)
38+
.setSubtitle(/* Subtitle of the fingerprint dialog */)
39+
.setDescription(/* Description of the fingerprint dialog */)
40+
.setNegativeButton(/* Negative button of the fingerprint dialog */);
41+
```
42+
43+
#### Kotlin:
44+
```kotlin
45+
val dialogBuilder = FingerprintDialogBuilder(this)
46+
.set Title(/* Title of the fingerprint dialog */)
47+
.setSubtitle(/* Subtitle of the fingerprint dialog */)
48+
.setDescription(/* Description of the fingerprint dialog */)
49+
.setNegativeButton(/* Negative button of the fingerprint dialog */)
50+
```
51+
52+
- ### Implement callbacks and show the dialog.
53+
- Implement the `AuthenticationCallback` to get callbacks for error or success from the fingerprint authentication dialog.
54+
55+
#### Java:
56+
```java
57+
final AuthenticationCallback callback = new AuthenticationCallback() {
58+
@Override
59+
public void fingerprintAuthenticationNotSupported() {
60+
// Device doesn't support fingerprint authentication. May be device doesn't have fingerprint hardware or device is running on Android below Marshmallow.
61+
// Switch to alternate authentication method.
62+
}
63+
64+
@Override
65+
public void hasNoFingerprintEnrolled() {
66+
// User has no fingerprint enrolled.
67+
// Application should redirect the user to the lock screen settings.
68+
// FingerprintUtils.openSecuritySettings(this)
69+
}
70+
71+
@Override
72+
public void onAuthenticationError(final int errorCode, @Nullable final CharSequence errString) {
73+
// Unrecoverable error. Cannot use fingerprint scanner. Library will stop scanning for the fingerprint after this callback.
74+
// Switch to alternate authentication method.
75+
}
76+
77+
@Override
78+
public void onAuthenticationHelp(final int helpCode, @Nullable final CharSequence helpString) {
79+
// Authentication process has some warning. such as "Sensor dirty, please clean it."
80+
// Handle it if you want. Library will continue scanning for the fingerprint after this callback.
81+
}
82+
83+
@Override
84+
public void authenticationCanceledByUser() {
85+
// User canceled the authentication by tapping on the cancel button (which is at the bottom of the dialog).
86+
}
87+
88+
@Override
89+
public void onAuthenticationSucceeded() {
90+
// Authentication success
91+
// Your user is now authenticated.
92+
}
93+
94+
@Override
95+
public void onAuthenticationFailed() {
96+
// Authentication failed.
97+
// Library will continue scanning the fingerprint after this callback.
98+
}
99+
};
100+
```
101+
102+
#### Kotlin:
103+
```kotlin
104+
val callback = object : AuthenticationCallback {
105+
106+
override fun fingerprintAuthenticationNotSupported() {
107+
// Device doesn't support fingerprint authentication. May be device doesn't have fingerprint hardware or device is running on Android below Marshmallow.
108+
// Switch to alternate authentication method.
109+
}
110+
111+
override fun hasNoFingerprintEnrolled() {
112+
// User has no fingerprint enrolled.
113+
// Application should redirect the user to the lock screen settings.
114+
// FingerprintUtils.openSecuritySettings(this@SecureActivity)
115+
}
116+
117+
override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) {
118+
// Unrecoverable error. Cannot use fingerprint scanner. Library will stop scanning for the fingerprint after this callback.
119+
// Switch to alternate authentication method.
120+
}
121+
122+
override fun onAuthenticationHelp(helpCode: Int, helpString: CharSequence?) {
123+
// Authentication process has some warning. such as "Sensor dirty, please clean it."
124+
// Handle it if you want. Library will continue scanning for the fingerprint after this callback.
125+
}
126+
127+
override fun authenticationCanceledByUser() {
128+
// User canceled the authentication by tapping on the cancel button (which is at the bottom of the dialog).
129+
}
130+
131+
override fun onAuthenticationSucceeded() {
132+
// Authentication success
133+
// Your user is now authenticated.
134+
}
135+
136+
override fun onAuthenticationFailed() {
137+
// Authentication failed.
138+
// Library will continue scanning the fingerprint after this callback.
139+
}
140+
}
141+
```
142+
143+
- Show the dialog and start fingerprint authentication.
144+
145+
#### Java:
146+
```java
147+
dialogBuilder.show(getSupportFragmentanager(), callback);
148+
```
149+
150+
#### Kotlin:
151+
```kotlin
152+
dialogBuilder.show(supportFragmentManager, callback)
153+
```
154+
155+
## Screenshots:
156+
157+
|Authentication success|Authentication fail|
158+
|:---:|:---:|
159+
|![success-demo.gif](/.github/auth_success.gif)|![ruler-view-demo.gif](/.github/auth_failed.gif)|
160+
161+
162+
## What to try this out?
163+
- You can download the sample apk from [here](https://github.com/kevalpatel2106/FingerprintDialogCompat/releases) and play with it.
164+
165+
7166
## Want to contribute?
8167
Every small or large contribution to this project is appreciated. Make sure you read the [contribution guide](/.github/CONTRIBUTING.md) before generating the pull request.
9168

build.gradle

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
/*
2-
* Copyright 2018 Keval Patel
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance wit
5-
* the License. You may obtain a copy of the License at
6-
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
10-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
11-
* the specific language governing permissions and limitations under the License.
2+
* Copyright (c) 2018. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
3+
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
4+
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
5+
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
6+
* Vestibulum commodo. Ut rhoncus gravida arcu.
127
*/
138

149
// Top-level build file where you can add configuration options common to all sub-projects/modules.
@@ -21,7 +16,7 @@ buildscript {
2116
jcenter()
2217
}
2318
dependencies {
24-
classpath 'com.android.tools.build:gradle:3.1.0'
19+
classpath 'com.android.tools.build:gradle:3.1.1'
2520
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2621
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
2722
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

0 commit comments

Comments
 (0)