forked from Kila2/libstdc-.6.0.9.tbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity2.java
87 lines (58 loc) · 2.93 KB
/
MainActivity2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.example.myapplication;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.util.concurrent.Executor;
public class MainActivity2 extends AppCompatActivity {
BiometricPrompt biometricPrompt;
ConstraintLayout mMainLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
mMainLayout = findViewById(R.id.main_layout);
BiometricManager biometricManager = BiometricManager.from(this);
switch (biometricManager.canAuthenticate()) {
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
Toast.makeText(getApplicationContext(), "Device doesn't have fingerprint service", Toast.LENGTH_SHORT).show();
break;
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
Toast.makeText(getApplicationContext(), "Currently fingerprint sensor not working", Toast.LENGTH_SHORT).show();
break;
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
Toast.makeText(getApplicationContext(), "No fingerprint assigned", Toast.LENGTH_SHORT).show();
break;
case BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED:
case BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED:
case BiometricManager.BIOMETRIC_STATUS_UNKNOWN:
case BiometricManager.BIOMETRIC_SUCCESS:
break;
}
Executor executor = ContextCompat.getMainExecutor(this);
biometricPrompt = new BiometricPrompt(MainActivity2.this, executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
}
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(getApplicationContext(), "login success", Toast.LENGTH_SHORT).show();
mMainLayout.setVisibility(View.VISIBLE);
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
});
BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder().setTitle("Attendance")
.setDescription("Use fingerprint to Login").setNegativeButtonText("cancel").build();
biometricPrompt.authenticate(promptInfo);
}
}