mirror of
https://github.com/danog/termux-api.git
synced 2024-12-02 09:17:50 +01:00
Update to BiometricManager
This commit is contained in:
parent
67954de363
commit
f9041daf6b
@ -1,12 +1,12 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 29
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.termux.api"
|
applicationId "com.termux.api"
|
||||||
minSdkVersion 24
|
minSdkVersion 24
|
||||||
targetSdkVersion 28
|
targetSdkVersion 29
|
||||||
versionCode 44
|
versionCode 44
|
||||||
versionName "0.44"
|
versionName "0.44"
|
||||||
}
|
}
|
||||||
@ -38,9 +38,9 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.android.material:material:1.0.0'
|
implementation 'com.google.android.material:material:1.2.1'
|
||||||
implementation 'androidx.biometric:biometric:1.0.0-alpha04'
|
implementation 'androidx.biometric:biometric:1.0.1'
|
||||||
implementation "androidx.media:media:1.1.0"
|
implementation "androidx.media:media:1.2.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
task versionName {
|
task versionName {
|
||||||
|
@ -12,8 +12,8 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.biometric.BiometricConstants;
|
import androidx.biometric.BiometricConstants;
|
||||||
|
import androidx.biometric.BiometricManager;
|
||||||
import androidx.biometric.BiometricPrompt;
|
import androidx.biometric.BiometricPrompt;
|
||||||
import androidx.core.hardware.fingerprint.FingerprintManagerCompat;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import com.termux.api.util.ResultReturner;
|
import com.termux.api.util.ResultReturner;
|
||||||
@ -71,7 +71,7 @@ public class FingerprintAPI {
|
|||||||
resetFingerprintResult();
|
resetFingerprintResult();
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(context);
|
BiometricManager fingerprintManagerCompat = BiometricManager.from(context);
|
||||||
// make sure we have a valid fingerprint sensor before attempting to launch Fingerprint activity
|
// make sure we have a valid fingerprint sensor before attempting to launch Fingerprint activity
|
||||||
if (validateFingerprintSensor(context, fingerprintManagerCompat)) {
|
if (validateFingerprintSensor(context, fingerprintManagerCompat)) {
|
||||||
Intent fingerprintIntent = new Intent(context, FingerprintActivity.class);
|
Intent fingerprintIntent = new Intent(context, FingerprintActivity.class);
|
||||||
@ -120,16 +120,21 @@ public class FingerprintAPI {
|
|||||||
* Ensure that we have a fingerprint sensor and that the user has already enrolled fingerprints
|
* Ensure that we have a fingerprint sensor and that the user has already enrolled fingerprints
|
||||||
*/
|
*/
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
protected static boolean validateFingerprintSensor(Context context, FingerprintManagerCompat fingerprintManagerCompat) {
|
protected static boolean validateFingerprintSensor(Context context, BiometricManager biometricManager) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
|
||||||
if (!fingerprintManagerCompat.isHardwareDetected()) {
|
if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) {
|
||||||
Toast.makeText(context, "No fingerprint scanner found!", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "No fingerprint scanner found!", Toast.LENGTH_SHORT).show();
|
||||||
appendFingerprintError(ERROR_NO_HARDWARE);
|
appendFingerprintError(ERROR_NO_HARDWARE);
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE) {
|
||||||
|
Toast.makeText(context, "No fingerprint scanner available!", Toast.LENGTH_SHORT).show();
|
||||||
|
appendFingerprintError(ERROR_NO_HARDWARE);
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fingerprintManagerCompat.hasEnrolledFingerprints()) {
|
if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED) {
|
||||||
Toast.makeText(context, "No fingerprints enrolled", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "No fingerprints enrolled", Toast.LENGTH_SHORT).show();
|
||||||
appendFingerprintError(ERROR_NO_ENROLLED_FINGERPRINTS);
|
appendFingerprintError(ERROR_NO_ENROLLED_FINGERPRINTS);
|
||||||
result = false;
|
result = false;
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/grant_permission_description"
|
|
||||||
android:layout_marginLeft="32dp"
|
|
||||||
android:layout_marginRight="32dp"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<Button
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:text="@string/grant_permission"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:onClick="onOkButton"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
Loading…
Reference in New Issue
Block a user