Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带外部指纹感应设备的android应用程序中的指纹感应_Android_Sqlite_Authentication_Fingerprint - Fatal编程技术网

带外部指纹感应设备的android应用程序中的指纹感应

带外部指纹感应设备的android应用程序中的指纹感应,android,sqlite,authentication,fingerprint,Android,Sqlite,Authentication,Fingerprint,我是android studio的初学者。我们有一个外部指纹感应设备。我们必须在android应用程序中检测指纹(支持所有android版本)。如果我下载指纹sdk,它是否支持所有外部设备?我不知道从哪里开始。有人能帮我做这件事吗?请使用以下方法。 公共类指纹{ private static final String KEY_NAME = "PS"; KeyguardManager keyguardManager; FingerprintManager fingerprintManager; C

我是android studio的初学者。我们有一个外部指纹感应设备。我们必须在android应用程序中检测指纹(支持所有android版本)。如果我下载指纹sdk,它是否支持所有外部设备?我不知道从哪里开始。有人能帮我做这件事吗?

请使用以下方法。 公共类指纹{

private static final String KEY_NAME = "PS";
KeyguardManager keyguardManager;
FingerprintManager fingerprintManager;
Context context;
private KeyStore keyStore;
private Cipher cipher;


public FingerprintUtils(Context context) {
    this.context = context;

}


public void checkFingerprintValidations(FPValidationCallback callback) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        keyguardManager = (KeyguardManager) context.getSystemService(KEYGUARD_SERVICE);
        fingerprintManager = (FingerprintManager) context.getSystemService(FINGERPRINT_SERVICE);
        if (!fingerprintManager.isHardwareDetected()) {
            //Log.e("Test", "Your Device does not have a Fingerprint Sensor");
            callback.isHardwareAvailFalse();
            return;
        }
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            //Log.e("Test", "Fingerprint authentication permission not enabled");
            callback.isPermissionPermittedFalse();
            return;
        }
        if (!fingerprintManager.hasEnrolledFingerprints()) {
            //Log.e("Test", "Register at least one fingerprint in Settings");
            callback.isFingerRegisteredFalse();
            return;
        }
        if (!keyguardManager.isKeyguardSecure()) {
            //Log.e("Test", "Lock screen security not enabled in Settings");
            callback.isLockScreenSecurityFalse();
            return;
        }

        callback.continueOnFingerprint();
    } else {
        callback.isDevice23False();
    }


}

public void matchFingerPrintsNow(FPResultCallback FPResultCallback) {

    generateKey();

    if (cipherInit()) {
        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
        FingerprintHandler helper = new FingerprintHandler(context);

        helper.startAuth(fingerprintManager, cryptoObject, FPResultCallback);
    }

}


//--------------------------------------Used in this class private access------------------
private void generateKey() {
    try {
        keyStore = KeyStore.getInstance("AndroidKeyStore");
    } catch (Exception e) {
        e.printStackTrace();
    }

    KeyGenerator keyGenerator;
    try {
        keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
    } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
        throw new RuntimeException("Failed to get KeyGenerator instance", e);
    }

    try {
        keyStore.load(null);
        keyGenerator.init(new
                KeyGenParameterSpec.Builder(KEY_NAME,
                KeyProperties.PURPOSE_ENCRYPT |
                        KeyProperties.PURPOSE_DECRYPT)
                .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                .setUserAuthenticationRequired(true)
                .setEncryptionPaddings(
                        KeyProperties.ENCRYPTION_PADDING_PKCS7)
                .build());
        keyGenerator.generateKey();
    } catch (NoSuchAlgorithmException |
            InvalidAlgorithmParameterException
            | CertificateException | IOException e) {
        throw new RuntimeException(e);
    }
}


private boolean cipherInit() {
    try {
        cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
        throw new RuntimeException("Failed to get Cipher", e);
    }

    try {
        keyStore.load(null);
        SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME,
                null);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return true;
    } catch (KeyPermanentlyInvalidatedException e) {
        return false;
    } catch (KeyStoreException | CertificateException | UnrecoverableKeyException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
        throw new RuntimeException("Failed to init Cipher", e);
    }
}
}

公共接口FPValidationCallback{

void isHardwareAvailFalse();
void isPermissionPermittedFalse();
void isFingerRegisteredFalse();
void isLockScreenSecurityFalse();
void isDevice23False();`
void continueOnFingerprint();

}

到sqlite的连接在哪里?
void isHardwareAvailFalse();
void isPermissionPermittedFalse();
void isFingerRegisteredFalse();
void isLockScreenSecurityFalse();
void isDevice23False();`
void continueOnFingerprint();