我正在尝试通过指纹身份验证实现指纹解锁或删除锁定 View ,使用传感器现有的注册指纹进一步显示内容,但指纹身份验证在正常 Activity 中工作正常但在自定义 View 中不起作用,我也尝试过在我的自定义屏幕锁定应用程序中实现它,但它有冲突或可能是由于资源不可用而面临此错误“FINGERPRINT_ERROR_CANCELED”,错误代码为 5
我不确定是不是由于资源不可用,因为同时内置的安全密码/图案锁也使用相同的指纹传感器以及我自己的屏幕锁或自定义 View
这段代码运行良好 Activity 代码
fingerprintHandler = new FingerprintHandler();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
keyguardManager =
(KeyguardManager) getSystemService(KEYGUARD_SERVICE);
mFingerprintManager =
(FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
//
// generateKey();
// if (cipherInit()) {
// cryptoObject =
// new FingerprintManager.CryptoObject(cipher);
fingerprintHandler.setOnAuthenticationListener(new FingerprintManager.AuthenticationCallback() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
Toast.makeText(FingerprintNormalActivity.this,
"Authentication error\n" + "Error code" + errorCode + "\nError String" + errString,
Toast.LENGTH_LONG).show();
imageViewSmokeImages.setImageResource(R.drawable.fingerprinterror);
tvstatus.setText("Authentication error\n" + "Error code" + errorCode + "\nError String" + errString);
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onAuthenticationHelp(int helpCode, CharSequence helpString) {`enter code here`
Toast.makeText(FingerprintNormalActivity.this,
"Authentication help\n" + helpString,
Toast.LENGTH_LONG).show();
imageViewSmokeImages.setImageResource(R.drawable.help);
tvstatus.setText("Authentication help\n" + helpString);
}
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
Toast.makeText(FingerprintNormalActivity.this,
"Authentication succeeded.",
Toast.LENGTH_LONG).show();
imageViewSmokeImages.setImageResource(R.drawable.fingerprintsuccess);
tvstatus.setText("Authentication Successfull");
finish();
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onAuthenticationFailed() {
Toast.makeText(FingerprintNormalActivity.this,
"Authentication failed.",
Toast.LENGTH_LONG).show();
tvstatus.setText("Authentication failed");
imageViewSmokeImages.setImageResource(R.drawable.fingerprintfailed);
}
});
// new AuthenticateUser();
//// fingerprintHandler.startListening();
if (!getKeyStore())
return;
if (!createNewKey(false)) {
return;
}
if (!getCipher()) {
return;
}
if (!initCipher(Cipher.ENCRYPT_MODE)) {
return;
}
if (!initCryptObject()) {
return;
} else {
fingerprintHandler.startListening(cryptoObject);
}
// }
}
这是我要收听的指纹处理类
private static FingerprintManager.AuthenticationCallback mAuthenticationCallback;
private static CancellationSignal mCancellationSignal;
private static Context mContext;
@RequiresApi(api = Build.VERSION_CODES.M)
public class FingerprintHandler {
public void setOnAuthenticationListener(FingerprintManager.AuthenticationCallback listener) {
mAuthenticationCallback = listener;
}
public void startListening() {
if (isFingerScannerAvailableAndSet()) {
try {
mCancellationSignal = new CancellationSignal();
mFingerprintManager.authenticate(null, mCancellationSignal, 0 /* flags */, mAuthenticationCallback, new Handler(Looper.getMainLooper()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void startListening(FingerprintManager.CryptoObject cryptoObject) {
if (isFingerScannerAvailableAndSet()) {
try {
mCancellationSignal = new CancellationSignal();
mFingerprintManager.authenticate(cryptoObject, mCancellationSignal, 0 /* flags */, mAuthenticationCallback, new Handler(Looper.getMainLooper()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void stopListening() {
if (isFingerScannerAvailableAndSet()) {
try {
mCancellationSignal.cancel();
mCancellationSignal = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
public boolean isFingerScannerAvailableAndSet() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return false;
if (ActivityCompat.checkSelfPermission(FingerprintNormalActivity.this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(FingerprintNormalActivity.this, "User hasn't granted permission to use Fingerprint", Toast.LENGTH_LONG).show();
return false;
}
if (mFingerprintManager == null){
Toast.makeText(FingerprintNormalActivity.this,
"mFingerprintManager is null",
Toast.LENGTH_LONG).show();
tvstatus.setText("mFingerprintManager is null");
return false;
}
if (!mFingerprintManager.isHardwareDetected()) {
Toast.makeText(FingerprintNormalActivity.this,
"fingerprint hardware not present or not functional",
Toast.LENGTH_LONG).show();
tvstatus.setText("fingerprint hardware not present or not functional");
return false;
}
if (!mFingerprintManager.hasEnrolledFingerprints()) {
Toast.makeText(FingerprintNormalActivity.this,
"no fingerprint enrolled/saved",
Toast.LENGTH_LONG).show();
tvstatus.setText("no fingerprint enrolled/saved");
return false;
}
return true;
}
}
最佳答案
参见 this issue .这似乎发生在大多数设备上,需要作为特殊情况处理。似乎对我有用的是在这个错误上停止指纹监听器,然后再次重新启动它。
@Override
public void onAuthenticationError(int errMsgId, CharSequence errString) {
if (errMsgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED){
stopListening();
restartListeningToFingerprint();
}
}
在 restartListening() 方法中,我只是用一个新的 Cipher 实例调用 startListening。这似乎适用于我拥有的所有设备。但我确实看到一些三星设备出现一些随机的致命异常,这可能是它的副作用。我很好奇其他人是如何处理这个错误的。
关于android - 自定义 View android 中的 "FINGERPRINT_ERROR_CANCELED"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42921294/
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我正在使用这个:4.times{|i|assert_not_equal("content#{i+2}".constantize,object.first_content)}我之前声明过局部变量content1content2content3content4content5我得到的错误NameError:wrongconstantnamecontent2这个错误是什么意思?我很确定我想要content2=\ 最佳答案 你必须用一个大字母来调用ruby常量:Content2而不是content2。Aconstantnamestart
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que