Android6.0 Fingerprint Identification development

Source: Internet
Author: User

Recently in the Android fingerprint related features, Google in android6.0 and above the version number of fingerprint identification has been officially supported. At that time between Fingerprintmanager and Fingerprintmanagercompat between the two tangled. Use Fingerprintmanager to introduce the COM.ANDROID.SUPPORT:APPCOMPAT-V7 package. Given the size of the package, it is decided to use the V4 Compatibility Pack Fingerprintmanagercompat. The main implementation of the tool class Fingerprintutil: Verify that the phone supports the fingerprint Identification Method Callfingerprintverify (), mainly verify whether the phone hardware support (6.0 and above), there is no input fingerprint, and then there is no lock screen to open password. Verify that the failure is capable of corresponding callback processing for the recognition success.
  Public  class fingerprintutil{    PrivateFingerprintmanagercompat Mfingerprintmanager;PrivateKeyguardmanager Mkeymanager;PrivateCancellationsignal mcancellationsignal;PrivateActivity mactivity; Public Fingerprintutil(Context CTX)        {mactivity = (Activity) ctx;        Mfingerprintmanager = Fingerprintmanagercompat.from (mactivity);    Mkeymanager = (Keyguardmanager) mactivity.getsystemservice (Context.keyguard_service); } Public void callfingerprintverify(FinalIfingerprintresultlistener listener) {if(!ishardwaredetected ()) {return; }if(!ishasenrolledfingerprints ()) {if(Listener! =NULL) {Listener.onnoenroll (); }return; }if(!iskeyguardsecure ()) {if(Listener! =NULL) {listener.oninsecurity (); }return; }if(Listener! =NULL) {Listener.onsupport (); }if(Listener! =NULL) {Listener.onauthenticatestart (); }if(Mcancellationsignal = =NULL) {mcancellationsignal =NewCancellationsignal (); }Try{Mfingerprintmanager.authenticate (NULL,0, Mcancellationsignal,NewFingerprintmanagercompat.authenticationcallback () {//Multiple attempts fail to go onauthenticationerror. will stop responding for some time. Excessive number of prompt attempts. Please try again later.

@Override Public void Onauthenticationerror(intErrmsgid, Charsequence errstring) {if(Listener! =NULL) Listener.onauthenticateerror (Errmsgid, errstring); }//Fingerprint verification failed to go this way, such as Xiaomi 4 authentication failed to go onauthenticationfailed, the 5th time to go onauthenticationerror @Override Public void onauthenticationfailed() {if(Listener! =NULL) listener.onauthenticatefailed (); }@Override Public void Onauthenticationhelp(intHelpmsgid, Charsequence helpstring) {if(Listener! =NULL) Listener.onauthenticatehelp (Helpmsgid, helpstring); }This function is recalled when a validated fingerprint succeeds. And then stop listening to fingerprint sensor . @Override Public void onauthenticationsucceeded(Fingerprintmanagercompat.authenticationresult result) {if(Listener! =NULL) listener.onauthenticatesucceeded (result); } },NULL); }Catch(Exception e) {E.printstacktrace (); } }/** * Whether to enter fingerprints, some devices even entered the fingerprint, but did not open the lock screen password this method or return false * * @return * * Private Boolean ishasenrolledfingerprints() {Try{returnMfingerprintmanager.hasenrolledfingerprints (); }Catch(Exception e) {return false; } }/** * Do you have fingerprint identification hardware support * * @return */ Public Boolean ishardwaredetected() {Try{returnMfingerprintmanager.ishardwaredetected (); }Catch(Exception e) {return false; } }/** * Infer whether to turn on the lock screen password * * @return * * Private Boolean iskeyguardsecure() {Try{returnMkeymanager.iskeyguardsecure (); }Catch(Exception e) {return false; } }/** * Fingerprint Recognition Callback interface * / Public interface ifingerprintresultlistener { voidOninsecurity ();voidOnnoenroll ();voidOnsupport ();voidOnauthenticatestart ();voidOnauthenticateerror (intErrmsgid, Charsequence errstring);voidOnauthenticatefailed ();voidOnauthenticatehelp (intHelpmsgid, Charsequence helpstring);voidonauthenticatesucceeded (fingerprintmanagercompat.authenticationresult result); } Public void cancelauthenticate() {if(Mcancellationsignal! =NULL) {mcancellationsignal.cancel (); Mcancellationsignal =NULL; } } Public void OnDestroy() {cancelauthenticate (); Mkeymanager =NULL; Mfingerprintmanager =NULL; }

Some references were made and some verification was done. Get some conclusions: 1, when the fingerprint recognition failed, will call the Onauthenticationfailed () method, this time the fingerprint sensor is not closed, Google native system gave us 5 retry opportunities, that is, After 4 successive calls to the onauthenticationfailed () method, the 5th time calls the Onauthenticateerror (int errmsgid, Charsequence errstring) method, at which time errmsgid== 7.

2, each time authorization, even if not to verify. Cancel will go onauthenticateerror (int errmsgid, Charsequence errstring) method, among errmsgid==5,3, when the system calls Onauthenticationerror () and onauthenticationsucceeded (), the sensor shuts down, only we authorize again. The ability to continue using the fingerprint recognition function after calling the authenticate () method again.

4, compatible with android6.0 under the system, do not use Fingerprintmanagercompat, less than the system version number M. Fingerprintmanagercompat regardless of whether the mobile phone has a fingerprint identification module, all feel that there is no fingerprint identification, can be used Fingerprintmanager to do. 5, considering the safety factors, the best authenticate (Cryptoobject Crypto, cancellationsignal cancel, int flags, Authenticationcallback callback, Handler Handler) increases cryptoobject. Crypto this is an object of a cryptographic class that the fingerprint scanner uses to infer the legitimacy of the authentication result.

This object can be null, but this is the case. This means that the app unconditionally trusts the results of the authentication and this process can be compromised. Data can be tampered with. This is the risk that the app must take in this case.

So. It is recommended that this parameter not be null. The instantiation of this class is a bit cumbersome, mainly implemented using the Javax security interface.

Android6.0 Fingerprint Identification development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.