我制作了一个使用指纹传感器停用服务的android应用,但是当我锁定设备(让服务在后台运行)然后恢复该应用时,会出现来自“ onAuthenticationError”的错误消息方法,它不会使用正确的指纹或错误的指纹进行更新,只是停留在该错误上,直到重新启动应用程序为止。
@TargetApi(Build.VERSION_CODES.M)
public class HuellaDigital extends
FingerprintManager.AuthenticationCallback {
private Context context;
TextView textView;
ImageView imageView;
Vibrator vibrator;
Servicio servicio = new Servicio();
public HuellaDigital(Context context) {
this.context = context;
}
public void startAuth(FingerprintManager fingerprintManager,
FingerprintManager.CryptoObject cryptoObject) {
CancellationSignal cancellationSignal = new CancellationSignal();
fingerprintManager.authenticate(cryptoObject, cancellationSignal, 0,
this, null);
}
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
this.update("Error al leer la huella, intente de nuevo. " + errString,
false);
imageView =((Activity) context).findViewById(R.id.img);
imageView.setImageResource(R.drawable.ic_error);
servicio.Activado = true;
}
@Override
public void onAuthenticationFailed() {
this.update("Huella no registrada, favor de usar una registrada",
false);
imageView =((Activity) context).findViewById(R.id.img);
imageView.setImageResource(R.drawable.ic_error);
servicio.Activado = true;
}
@Override
public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
this.update("Error: " + helpString, false);
servicio.Activado = false;
}
@Override
public void
onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result)
{
this.update("Proteccion desactivada.", true);
servicio.Activado = false;
context.stopService(new Intent(context, Servicio.class));
imageView =((Activity) context).findViewById(R.id.img);
imageView.setImageResource(R.drawable.ic_done);
vibrator =
(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.cancel();
}
public void update(String s, boolean b) {
Servicio servicio = new Servicio();
textView = (TextView) ((Activity) context).findViewById(R.id.txtMsg);
textView.setText(s);
if (b == false){
textView.setTextColor(ContextCompat.getColor(context,
R.color.ColorSecundario));
}else {
textView.setTextColor(ContextCompat.getColor(context,
R.color.ColorDone));
}
}
}