preface

Let’s start by explaining why this library was published. Many people who have not done the fingerprint related functions must think as I did at the beginning: fingerprint payment is very simple to call the official packaged Api, familiar with several Api things. However, this is just fingerprint identification, and the design of real fingerprint identification applications has a lot of problems. Here is an example of the application scenario of fingerprint payment.

Our expectations:

(1) Fingerprint payment can be bound with finger, which is the same as wechat payment: a fingerprint is entered when it is opened, and only the fingerprint bound at that time can be used for payment each time

(2) if the above can not go, it can only be the same as China Merchants Bank fingerprint login: open fingerprint login verification fingerprint, after verification, each login can be through the verification of the input fingerprint is any fingerprint in the input system. If you open your fingerprint and input a new fingerprint in the system, the next time you log in China Merchants Bank with your fingerprint, you will be reminded that your fingerprint has changed.

Focus on

You don’t have to worry about versioning, you don’t have to worry about any interfaces, you just have to deal with your own business.

This library

API ‘com. Codersun: fingermanager: 1.0.2’

* making links

Github.com/Likeyong/Fi…

Fingerprint payment schemes exist

  • Use wechat open source Soter library

The advantage of this scheme is stability, it is said that wechat fingerprint payment is to use this scheme, and domestic equipment manufacturers cooperation. Which finger can be located and the fingerprint Id can be obtained. The disadvantage is that Huawei mobile phones and some foreign manufacturers (not cooperating with Soter) are not supported. Although the wechat client is huawei fingerprint support. However, this framework is not supported for the time being.(it was said to be supported a long time ago, so far it has not been supported.) I support Huawei anyway

  • Use the official system Api

Advantages: Supports all fingerprint devices above Android 6.0 (80% of CMB will use this scheme)

Disadvantages: 1. Can not obtain the fingerprint Id, can not be bound with the finger, can also determine whether the fingerprint database changes to ensure security

2. Need for Android 6.0 and Android 9.0 adaptation: Android 9.0 requires their own fingerprint recognition popover style, but Android 9.0 started by the unified system popover implementation (different manufacturers may not be the same)

Self-actualized pit

Here is a list of the problems with the fingerprint login of China Merchants Bank through the official API, which is the advantages of this library:

1. Determine if your phone’s fingerprint database has changed

2. You need to adapt to the Android version. If the Android version is larger than 6.0 and smaller than 9.0, you need to implement the fingerprint identification popup by yourself. On Android P, use the latest Api to call the fingerprint unified popover

3. The fingerprint identification callback fails in two cases: if the fingerprint identification fails, or if the user cancels the fingerprint identification, the fingerprint identification callback fails. So there is a distinction to be made between the two cases, and there is no direct excuse for the official API.

Fingerprint identification API interpretation

I won’t write it here, because someone has done a very good job on the official API reading, and the link below explains how to use the API in such detail that it’s rewarding to read his article after I’ve written my own library. But his library doesn’t seem to solve the above three problems.

Mp.weixin.qq.com/s/IhNdod3rB…

Live ammunition

Using the library, you can do all of the above with this code:

1. Check whether the device supports fingerprint: the device supports fingerprint authentication in three ways: (1) the device does not have a fingerprint reader. (2) The device has a fingerprint reader but does not have fingerprint data

2. Changes in fingerprint database data of corresponding mobile phones

3. Cancels fingerprint identification and fails fingerprint identification

4. Identify Android M and P

The switch (FingerManager checkSupport (MainActivity. This)) {case DEVICE_UNSUPPORTED: showToast (" your device does not support the fingerprint "); break; Case SUPPORT_WITHOUT_DATA: showToast(" Please verify after fingerprint entry "); break; case SUPPORT: Fingermanager.build ().setApplication(getApplication()).setTitle(" fingerprint verification ").setdes (" Please press the fingerprint ").setnegativeText (" Cancel ") .setFingerDialogApi23(new MyFingerDialog()) .setFingerCheckCallback(new SimpleFingerCheckCallback() { @Override public Void onSucceed() {void onSucceed(); } @override public void onError(String error) {public void onError(String error); } @override public void onCancel() {showToast(" you cancelled the recognition "); } }) .setFingerChangeCallback(new AonFingerChangeCallback() { @Override protected void onFingerDataChange() { ShowToast (" Fingerprint data has changed "); } }) .create() .startListener(MainActivity.this); break; }Copy the code




Customize android M pop-ups

If you want to customize android M’s fingerprint popover, it’s easy, you just need to:

  1. Inherited AFingerDialog class
  2. Initialize your own layout in onCreateView
  3. The four callbacks onSucceed(), onFailed (), onHelp (), and onError () should be implemented. These four callbacks are recommended to only perform UI-related operations. The logical operations have provided callback interfaces externally.

Popup window callback

  1. OnSucceed: The fingerprint identification succeeds and the popover can be closed directly
  2. OnFailed: Callback when the identified finger is not registered, but validation can continue
  3. OnHelp: the fingerprint recognition is not correct, will prompt, finger do not move a wide range of information, can continue to verify
  4. OnError: Fingerprint identification failed completely and verification cannot continue

A sequence of fingerprint recognition events looks like this: Start recognition –> (onHelp/onFaild) (zero or more) –> onSucceed/onError

code

public class MyFingerDialog extends AFingerDialog implements View.OnClickListener { private TextView titleTv; private TextView desTv; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View view = inflater.inflate(R.layout.my_dialog_finger, null); titleTv = view.findViewById(com.codersun.fingerprintcompat.R.id.finger_dialog_title_tv); desTv = view.findViewById(com.codersun.fingerprintcompat.R.id.finger_dialog_des_tv); TextView cancelTv = view.findViewById(com.codersun.fingerprintcompat.R.id.finger_dialog_cancel_tv); cancelTv.setOnClickListener(this); return view; } @Override public void onSucceed() { dismiss(); } @override public void onFailed() {titletv.settext (); Destv. setText(" Can't even click a finger, go shit "); } @override public void onHelp(String help) {titletv. setText(titletv. setText); Destv. setText(" Can't even click a finger, go shit "); } @override public void onError(String error) {titletv. setText(titletv. setText); Destv. setText(" this can fail, what else can you do, do not disappear, represents I am a custom popover "); } @Override public void onCancelAuth() { } @Override public void onClick(View v) { dismiss(); If you do not set the custom popover, the default Android M popover will be fingerManager.build ().setApplication(getApplication()). .setTitle(" Fingerprint validation ").setdes (" Please press the fingerprint ").setnegativeText (" Cancel ").setFingerDialogAPI23 (new MyFingerDialog()) .setFingerCheckCallback()Copy the code

demo

android M

  • Fingerprint identification succeeded





  • The device has no fingerprint data





  • Fingerprint verification failed





  • Disabling fingerprint Identification





  • Custom fingerprint identification pop-ups








  • The fingerprint data has changed





android P

  • Fingerprint identification succeeded





  • Fingerprint identification failure





  • Cancel fingerprint identification





  • The fingerprint database is changed. Procedure





use

API ‘com. Codersun: fingermanager: 1.0.2’