Android fingerprint recognition function in simple analysis to actual combat (6.0 system solutions below) _android

Source: Internet
Author: User
Tags try catch

The term fingerprint recognition sounds familiar, but it's not used much in the actual development process. Google started with Android6.0 (API23) to provide standard fingerprint recognition support, and to provide external fingerprint identification related interface. In addition to fit 6.0 and above system, the main also provides 6.0 of the following equipment adaptation solutions.

Fingerprint identification use

A few of the uses of fingerprint identification are probably enumerated

    • System unlock
    • Apply Lock
    • Payment Certification
    • Common Login Authentication

Fingerprint identification Google Official document

Official Standard Library

Google offers few core classes related to fingerprint identification, the main class is Fingerprintmanager, and the main class relies on three internal classes, as shown in the following illustration:

Fingerprintmanager mainly provides three methods as follows:
The callback interface provided by the Fingerprintmanager.authenticationcallback class is as follows, with emphasis on distinguishing the parts of the red underlined callout
Start Fingerprint Identification interface

Read the above description, if you want to write the code will be easy

1. Androidmanifest Permission Statement

<uses-permission android:name= "Android.permission.USE_FINGERPRINT"/>

2. Get Fingermanager Service object

public static Fingerprintmanager Getfingerprintmanager {
  Fingerprintmanager Fingerprintmanager = null;
  try {
    Fingerprintmanager = (fingerprintmanager) context.getsystemservice (Context.fingerprint_service);
  } catch (Throwable e) {
    FPLog.log ("Have not class Fingerprintmanager");
  }
  return fingerprintmanager;
}

3. Start fingerprint identification

Mfingerprintmanager.authenticate (Cryptoobject, mcancellationsignal, 0, mauthcallback, NULL);

Parameter meaning reference document description, here is more complex to create Cryptoobject objects, if only simple test can be null, specific code reference article at the end of the project address provided

Official V4 Compatibility Pack

The above describes the most standard official fingerprint identification method, of course, the adaptation is certainly not so simple, because there are many device compatibility to consider, Google Follow-up V4 package provides a complete set of implementation, the implementation of the class and the above one by one corresponding, is to change a name (Fingerprintmanager changed to Fingerprintmanagercompat, witty discovery Compat is compatible meaning, so Google in the V4 package do some compatibility processing), do a lot of compatibility processing, The latter is recommended for official use. The class structure in the V4 package is as follows:
The class in the V4 package is used in accordance with the standard library above, which is not the same as the name. The standard fingerprint identification interface is introduced, and the fingerprint identification adaptation is analyzed below. If you want to do fingerprint identification related to the function, you need to fully understand the fingerprint identification associated with the pit.

Fingerprint Identification matching

There are many problems with fingerprint identification, which can be seen in the following three situations.

    1. Google official support for fingerprint identification of the standard interface is started in Android6.0, if the vendors are upgraded to 6.0 and hardware support, then we follow the standard fingerprint identification interface to use.
    2. If after the android6.0 is released, mobile phone manufacturers have not been able to upgrade, but engineers refer to the official Fingerprint identification code, porting the code to their 6.0 version of the system, or using the interface provided by Google itself to implement a fingerprint identification mechanism, just like the developer exposed interface, so that you can use the standard Mouth, but this situation is hard to say, the implementation of the bad may itself have a lot of bugs, adaptation is also more trouble, but at least it can be used.
    3. If the manufacturer had already done fingerprint identification before Google, it would certainly not be possible to use the official standard interface, and if the device was to be fitted, only the Third-party fingerprint Identification SDK provided by the manufacturer would be used.

In general, just follow the official Google Walk on the line, 6.0 of the following system directly does not support, this also eliminates a lot of adaptation problems. But if an app has a large number of Third-party vendors under 6.0, it has to support the fingerprint recognition function, then only to do support. For the three cases mentioned above, the preceding two scenarios are consistent in writing, just follow the official Google document, but no longer require api>=23 logic, the code will have a warning, and you must also use the Try Catch process exception capture. Because ghosts don't know what's going to happen inside the vendor system. (Red meter Note3, System 5.0 or 5.1, when the Mfingerprintmanager.hasenrolledfingerprints () method is invoked, an empty pointer exception is thrown inside). Third, if you want to support, only through the company's cooperation to find manufacturers to provide the SDK.

Fingerprint recognition Operation screenshot

This project supports only the previous two scenarios mentioned above, and the following is a screenshot of the Vivo V3 (System 5.1.1,api 22) device.
Main interface

Start fingerprint identification.

Fingerprint identification results

Action Animation Demo

Project Address
SOURCE Download: Source Download Address

Experience Summary

Although there are many problems in fingerprint identification, security is not perfect, but the convenience of fingerprint identification is really good experience, used in some do not need to pay attention to security performance products are completely OK. If you want to understand fingerprint identification, you want to know how fingerprint identification is suitable for different versions of the API, then this project is worth reference. Knowledge of this thing, perhaps when it will work, more than pressure body, learn more to understand is a good thing.

Pits on special equipment

LeTV X500 Android 6.0,api23

Do not follow the normal routine callback onauthenticationerror,onauthenticationfailed, the theory should be to identify the failure of the situation, it callback error, click to cancel fingerprint recognition will be the first callback error, if encountered this situation, Can only be based on the specific project environment to circumvent the adaptation.

Original link: http://www.cnblogs.com/popfisher/p/6063835.html

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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.