I have been developing my personal android app to store my passwords. (Since lastpass is paid for mobile). I currently use simple password authentication, but i would love to be able to take advantage of my fingerprint scanner.
In file AndroidManifest.xml:
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
In file MainActivity.java:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//Fingerprint API only available on from Android 6.0 (M)
FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
if (!fingerprintManager.isHardwareDetected()) {
// Device doesn't support fingerprint authentication
} else if (!fingerprintManager.hasEnrolledFingerprints()) {
// User hasn't enrolled any fingerprints to authenticate with
} else {
// Everything is ready for fingerprint authentication
}
}
but how do i actually authenticate phone owner using his fingerprints?
UPDATE:
I used Lubomir Babev's answer and its perfect. You fill the two methods that you implement onAuthSucceded, onAuthFailed to handle if authorizartion was successful and i also had to add some permission checks, because Android studio made me do it
public void startListening() {
if (isFingerScannerAvailableAndSet()) {
try {
if (ActivityCompat.checkSelfPermission(mContext.getApplicationContext(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
}
mFingerprintManager.authenticate(null, mCancellationSignal, 0 /* flags */, mAuthenticationCallback, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
and
public void startListening() {
if (isFingerScannerAvailableAndSet()) {
try {
if (ActivityCompat.checkSelfPermission(mContext.getApplicationContext(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
}
mFingerprintManager.authenticate(null, mCancellationSignal, 0 /* flags */, mAuthenticationCallback, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}