Android6.0指纹识别开发实例

Android M指纹的资料太少,经过一段时间阅读原生Android代码,写了以下例子,贡献出来给需要帮助的人。

  以下内容基于64位的高通CPU,搭载fpc1020芯片,此部分代码在原生android上做了更改,以应付工厂指纹的测试。原生android指纹录入需要采集10次(因不同的芯片而定)。

  代码简单说明:

  1. FingerPrintEnrollBase类:

  重要的是

Java代码
  1. public interface Listener {  
  2.         void onEnrollmentHelp(CharSequence helpString);  
  3.         void onEnrollmentError(int errMsgId, CharSequence errString);  
  4.         void onEnrollmentProgressChange(int steps, int remaining);  

  这个接口。

  1)onEnrollmentHelp函数:是下层返回的指纹操作帮助信息。

  2)onEnrollmentError函数是下层返回的错误信息,errMsgId是错误信息类型,其中1表示指纹硬件不可用,3表示超时,5表示操作已取消。errString是errMsgId对应的文字信息,有需要的自己实验就知道了。

  3)onEnrollmentProgressChange()函数是显示当前指纹的采集情况,steps:总共需要录入多少次;remaining是剩余多少次,我在此函数中有打印Log。

  2. FingerPrintActivity是主Activity类,FingerPrintEnrollBase是指纹Base类。

  需要特别说明的是,在FingerPrintEnrollBase类中有一句:private byte[] mToken = new byte[69];这个数组正常情况是通过输入密码后经由framework层向hal层申请的,我这里为了省去验证那一块的代码,通过sizeof(hw_auth_token_t)计算出来的为69,需要的请依此计算。我在代码里实验过,此数组如果不是69(在64位CPU上),将直接导致程序crach!

       fpc指纹的采集流程图:

Android6.0指纹识别开发实例

       源码如下:

       FingerPrintEnrollBase:

Java代码
  1. /* 
  2.  * Copyright (C) 2015 The Android Open Source Project 
  3.  * 
  4.  * Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  * you may not use this file except in compliance with the License. 
  6.  * You may obtain a copy of the License at 
  7.  * 
  8.  *      http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  * Unless required by applicable law or agreed to in writing, software 
  11.  * distributed under the License is distributed on an "AS IS" BASIS, 
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  * See the License for the specific language governing permissions and 
  14.  * limitations under the License 
  15.  */  
  16.   
  17. package com.mediatek.test;  
  18.   
  19. import android.app.Activity;  
  20. import android.app.Fragment;  
  21. import android.content.Context;  
  22. import android.hardware.fingerprint.FingerprintManager;  
  23. import android.os.Bundle;  
  24. import android.os.CancellationSignal;  
  25. import android.os.Handler;  
  26. import android.util.Log;  
  27. /** 
  28.  * local fragment to handle the state around fingerprint enrollment. 
  29.  */  
  30. public class FingerPrintEnrollBase extends Fragment {  
  31.   
  32.     private int mEnrollmentSteps = -1;  
  33.     private int mEnrollmentRemaining = 0;  
  34.     private Listener mListener;  
  35.     private boolean mEnrolling;  
  36.     private CancellationSignal mEnrollmentCancel;  
  37.     private Handler mHandler = new Handler();  
  38.     private byte[] mToken = new byte[69];//if byte length != sizeof(hw_auth_token_t), throws Exception  
  39.     private boolean mDone;  
  40.     private static final String TAG = "FingerPrintEnrollBase";  
  41.   
  42.     @Override  
  43.     public void onCreate(Bundle savedInstanceState) {  
  44.         super.onCreate(savedInstanceState);  
  45.         setRetainInstance(true);  
  46.     }  
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值