J'utilise BiometricPrompt pour permettre à l'utilisateur d'utiliser l'authentification par empreinte digitale pour se connecter à l'application J'ai fait ce qui suit dans ma classe PasswordActivity:
Caused by java.lang.IllegalArgumentException: Executor must not be null at android.hardware.biometrics.BiometricPrompt$Builder.setNegativeButton + 182(BiometricPrompt.java:182) at androidx.biometric.BiometricFragment.onCreate + 201(BiometricFragment.java:201) at androidx.fragment.app.Fragment.performCreate + 2414(Fragment.java:2414) at androidx.fragment.app.FragmentManagerImpl.moveToState + 1418(FragmentManagerImpl.java:1418) at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState + 1784(FragmentManagerImpl.java:1784) at androidx.fragment.app.FragmentManagerImpl.moveToState + 1861(FragmentManagerImpl.java:1861) at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange + 3269(FragmentManagerImpl.java:3269) at androidx.fragment.app.FragmentManagerImpl.dispatchCreate + 3223(FragmentManagerImpl.java:3223) at androidx.fragment.app.FragmentController.dispatchCreate + 190(FragmentController.java:190) at androidx.fragment.app.FragmentActivity.onCreate + 369(FragmentActivity.java:369) at androidx.appcompat.app.AppCompatActivity.onCreate + 85(AppCompatActivity.java:85)
C'est l'exception que je reçois. Dois-je définir?
setNegativeButton (CharSequence text, Executor executor, DialogInterface.OnClickListener listener) as well?
J'utilise l'implémentation 'androidx.biometric: biometric: 1.0.0-alpha03' cette version.
Executor executor = Executors.newSingleThreadExecutor(); FragmentActivity activity = this; final BiometricPrompt biometricPrompt = new BiometricPrompt(activity, executor, new BiometricPrompt.AuthenticationCallback() { @Override public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) { super.onAuthenticationError(errorCode, errString); if (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) { // user clicked negative button } else { //TODO: Called when an unrecoverable error has been encountered and the operation is complete. } } @Override public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); //TODO: Called when a biometric is recognized. final String decryptedText = decryptText(); runOnUiThread(new Runnable() { @Override public void run() { if (decryptedText != null && !decryptedText.isEmpty()) { editPassword.setText(decryptedText); buttonNext(); } } }); } @Override public void onAuthenticationFailed() { super.onAuthenticationFailed(); //TODO: Called when a biometric is valid but not recognized. } }); final BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder() .setTitle("My App")) .setSubtitle("Log on into the app")) .setNegativeButtonText("Cancel").toUpperCase()) .build(); if (sharedPreferenceManager.isFingerprintEnabled(this)) biometricPrompt.authenticate(promptInfo);
3 Réponses :
Essayez de mettre à jour la dépendance, la dernière version actuellement est déjà une release candidate:
implementation "androidx.biometric:biometric:1.0.0-rc01"
cette méthode n'est pas disponible dans AndroidX
androidx
BiometricPrompt.java ne l'a en effet pas. Le Executor
peut déjà être null
lors de la construction, car c'est là qu'il est passé et où le message d'erreur Executor ne doit pas être nul
existe.
Oui je suis d'accord. Je ne sais pas comment dois-je résoudre ce problème. Apparemment, je n'ai jamais rencontré ce crash, mais de nombreux appareils équipés d'Android 9 et 10 en production sont confrontés à ces problèmes.
Vous pouvez vérifier si executor! = Null
, avant d'essayer d'afficher l'invite ... cependant, en regardant de plus près le stack-trace, la dernière ligne est toujours android.hardware .biometrics.BiometricPrompt
et non androidx
... essayez la version 1.0.0-beta02
.
Merci Martin, je vais essayer et garder ce post à jour avec mes résultats
Le outil de suivi des problèmes ne semble pas avoir un tel bogue.
J'ai un problème similaire, mais l'exécuteur et le rappel que je passe ne sont pas nuls. stackoverflow.com/questions/58286606 /…
@MartinZeitler: le problème a été résolu lors de la mise à jour vers la dernière version 1.0.0-beta02, comme vous l'avez suggéré. Pouvez-vous s'il vous plaît mettre à jour votre réponse afin que je puisse l'accepter
Caused by java.lang.IllegalArgumentException: Executor must not be null at android.hardware.biometrics.BiometricPrompt$Builder.setNegativeButton + 182(BiometricPrompt.java:182) This indicates that the framework on the device you're testing is either not receiving the executor from the support library (bug in support library), or the framework itself has a bug.Could you try on a later version of the androidx.biometric library? Beta02 was recently released, a lot of things have been fixed since alpha03.Also, what device are you testing, if it's reproducible on Beta02 could you grab a bugreport via adb bugreport foo.zip and attach your sample app with the bug to the public issue tracker?
Pouvez-vous essayer de remplacer Executor executor = Executors.newSingleThreadExecutor ();
par:
private Handler handler = new Handler(); private Executor executor = new Executor() { @Override public void execute(Runnable command) { handler.post(command); } };
Ceci est selon le code donné dans ce tutoriel developer.android.com.