资源简介
指纹识别工具类,包括android 提供的和自己反射获得指纹库等各种信息
代码片段和文件信息
package com.bankeys.common;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.CancellationSignal;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.support.annotation.*;
//import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.widget.Toast;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.List;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import static android.content.Context.FINGERPRINT_SERVICE;
import static android.content.Context.KEYGUARD_SERVICE;
/**
* Created by 龙江虹 on 2017/6/19.
* Company:收付宝科技有限公司
* Email:ljh19910519@163.com
*
* 经测试 Andoid6.0和Android7.0 均能完美运行,其他版本未测试
*/
public class FingerprintUtils {
private Context context;
private KeyStore mKeyStore;
private KeyGenerator mKeyGenerator;
private String defaultKeyNsme = “bankeysDemo“;
private Cipher mCipher;
private FingerprintManager fingerprintManager;
private CancellationSignal cancellationSignal;
private static final String TAG = “Bankeys“;
private KeyguardManager keyguardManager;
private int fingerNum;
private boolean isWriteFingerNum = false;
private int newFingerprintNum;
private StringBuffer mFingerPrintGroupId;
//@RequiresApi(api = Build.VERSION_CODES.M)
@TargetApi(23)
public FingerprintUtils(Context context) {
this.context = context;
initManger();
createSymmetryKey();
initCipher();
}
@TargetApi(Build.VERSION_CODES.M)
//初始化管理类
private void initManger() {
fingerprintManager = (FingerprintManager) context.getSystemService(FINGERPRINT_SERVICE);
keyguardManager = (KeyguardManager) context.getSystemService(KEYGUARD_SERVICE);
cancellationSignal = new CancellationSignal();
}
//判断设备是否支持指纹功能
//@RequiresApi(api = Build.VERSION_CODES.M)
@TargetApi(23)
public boolean isDetected() {
if (ActivityCompat.checkSelfPermission(context Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
评论
共有 条评论