public void authenticate ( ) { if ( fingerprintSecureCallback != null ) { if ( cryptoObject != null ) { throw new RuntimeException ( "If you specify a CryptoObject you have to use FingerprintCallback" ) ; } cryptoObject = cipherHelper . getEncryptionCryptoObject ( ) ; if ( cryptoObject == null ) { fingerprintSecureCallback . onNewFingerprintEnrolled ( new FingerprintToken ( cipherHelper ) ) ; } } else if ( fingerprintCallback == null ) { throw new RuntimeException ( "You must specify a callback." ) ; } cancellationSignal = new CancellationSignal ( ) ; if ( fingerprintManager . isHardwareDetected ( ) && fingerprintManager . hasEnrolledFingerprints ( ) ) { fingerprintManager . authenticate ( cryptoObject , cancellationSignal , 0 , new FingerprintManager . AuthenticationCallback ( ) { @ Override public void onAuthenticationError ( int errorCode , CharSequence errString ) { super . onAuthenticationError ( errorCode , errString ) ; setStatus ( R . drawable . fingerprint_error , fingerprintError , circleError ) ; handler . postDelayed ( returnToScanning , delayAfterError ) ; if ( fingerprintSecureCallback != null ) { fingerprintSecureCallback . onAuthenticationError ( errorCode , errString . toString ( ) ) ; } else { fingerprintCallback . onAuthenticationError ( errorCode , errString . toString ( ) ) ; } } @ Override public void onAuthenticationHelp ( int helpCode , CharSequence helpString ) { super . onAuthenticationHelp ( helpCode , helpString ) ; setStatus ( R . drawable . fingerprint_error , fingerprintError , circleError ) ; handler . postDelayed ( returnToScanning , delayAfterError ) ; if ( fingerprintSecureCallback != null ) { fingerprintSecureCallback . onAuthenticationError ( helpCode , helpString . toString ( ) ) ; } else { fingerprintCallback . onAuthenticationError ( helpCode , helpString . toString ( ) ) ; } } @ Override public void onAuthenticationSucceeded ( final FingerprintManager . AuthenticationResult result ) { super . onAuthenticationSucceeded ( result ) ; handler . removeCallbacks ( returnToScanning ) ; setStatus ( R . drawable . fingerprint_success , fingerprintSuccess , circleSuccess ) ; if ( fingerprintSecureCallback != null ) { fingerprintSecureCallback . onAuthenticationSucceeded ( ) ; } else { fingerprintCallback . onAuthenticationSucceeded ( ) ; } tryCounter = 0 ; } @ Override public void onAuthenticationFailed ( ) { super . onAuthenticationFailed ( ) ; setStatus ( R . drawable . fingerprint_error , fingerprintError , circleError ) ; handler . postDelayed ( returnToScanning , delayAfterError ) ; handler . postDelayed ( checkForLimit , delayAfterError ) ; if ( fingerprintSecureCallback != null ) { fingerprintSecureCallback . onAuthenticationFailed ( ) ; } else { fingerprintCallback . onAuthenticationFailed ( ) ; } } } , null ) ; } else { Log . e ( TAG , "Fingerprint scanner not detected or no fingerprint enrolled. Use FingerprintView#isAvailable(Context) before." ) ; } }
start fingerprint scan