Iva*_*kov 4 android fingerprint
我在Android上有一个项目,minSDK = 17,targetSDK = 23.我们在这个项目中使用FingerprintManager类进行了指纹认证(它在SDK23中添加).我们添加了SDK版本检查,因此如果SDK <23,我们不会使用与指纹相关的任何内容.但在较旧的SDK版本中,应用程序的行为是不可预测的:在某些版本的应用程序上只是崩溃,在其他版本上 - 指纹无法正常工作(所以,没关系).
我的问题:
1)minSDK = 17的任何好的且易于实现的库可以识别指纹吗?2)如何在SDK <23的设备中避免应用程序崩溃?崩溃错误:
E/dalvikvm: Could not find class 'android.hardware.fingerprint.FingerprintManager', referenced from method nl.intratuin.LoginActivity.loginByFingerprint
E/AndroidRuntime: FATAL EXCEPTION: main java.lang.VerifyError:
LoginActivity at java.lang.Class.newInstanceImpl(Native Method)
Run Code Online (Sandbox Code Playgroud)
一些新信息:使用本教程创建HelloWorld指纹项目:http: //www.techotopia.com/index.php/An_Android_Fingerprint_Authentication_Tutorial 找到问题的根源:FingerprintDemoActivity-> cipherInit:
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);
}
Run Code Online (Sandbox Code Playgroud)
第一个阻止整个应用程序错误我上面提到的错误.当然,我可以删除此catch(此异常扩展InvalidKeyException,因此将被处理),并在出现任何异常时返回false.这有更好的方法吗?
Iva*_*kov 13
我想,我找到了可接受的解决方案:捕获KeyPermanentlyInvalidatedException,但InvalidKeyException.这一切都很好.仍然不知道这个异常是如何崩溃的整个应用程序...
它也发生在我身上..即使我使用:if(Build.VERSION.SDK_INT> = Build.VERSION_CODES.M)..我的应用程序在android 4.4- kitkat崩溃.所以最终问题出现在catches部分的initCipher方法中 - 请参阅下面的代码(即使我不想因为它针对M及以上......非常奇怪的行为而到达那里......):
@TargetApi(Build.VERSION_CODES.M)
private boolean initCipher() {
try {
mKeyStore.load(null);
SecretKey key = (SecretKey) mKeyStore.getKey(KEY_NAME, null);
mCipher.init(Cipher.ENCRYPT_MODE, key);
return true;
} catch (KeyStoreException | CertificateException | UnrecoverableKeyException | IOException
| NoSuchAlgorithmException e) {
throw new RuntimeException("Failed to init Cipher", e);
} catch (InvalidKeyException e) {
e.printStackTrace();
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
显然,捕获的顺序很重要.所以只要确保按我提到的那样写.
| 归档时间: |
|
| 查看次数: |
5337 次 |
| 最近记录: |