Android 6.0+Fingerprint心得
我的demo链接
google官方demo
google相关API:android.support.v4.hardware.fingerprint
具体实现:实现某个功能模块我认为最有效的方法就是找到该功能模块的启动方法(看别人代码我认为很有效的方法),然后逆推看明白整个工作流程。千万不要盲目的从第一行代码慢慢的一行一行的看,这样效率会很低,也很乏味。步入正题,先找到Fingerprint的启动方法:
/*
Request authentication of a crypto object. This call warms up the fingerprint hardware and starts scanning for a fingerprint. It terminates when onAuthenticationError(int, CharSequence) or {@link AuthenticationCallback#onAuthenticationSucceeded(AuthenticationResult) is called, at which point the object is no longer valid. The operation can be canceled by using the provided cancel object.
*/
public void authenticate (FingerprintManagerCompat.CryptoObject crypto,
int flags,
CancellationSignal cancel,
FingerprintManagerCompat.AuthenticationCallback callback,
Handler handler)
这个方法是FingerprintManagerCompat类的公有方法,然后想办法把这个方法需要的几个参数给他,最后在调用他,这个功能大体就实现了;嗯,中间当然还有一些细节需要注意,比如如何实例化那几个类,可不可以传null之类的。下面给出我demo的具体代码,大家挑重要的看,然后按我说的方法看(这个方法authenticate着手哦),试试效果。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.contacts.lhj.myfingerprinttest">
<!--指纹权限-->
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<act