BiometricPrompt.Builder.setDeviceCredentialAllowed(boolean)方法过时了,怎么破。

本文主要是介绍BiometricPrompt.Builder.setDeviceCredentialAllowed(boolean)方法过时了,怎么破。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Android R中已经将该API setDeviceCredentialAllowed() 标记为@Deprecated,即API=30开始不推荐使用该API。

先来看看官方API怎么说?

API29_biometricPrompt

明确说,请使用setAllowedAuthenticators(int)代替。

API30_BiometricPrompt

怎么用,上图API已经说的很清晰,举个栗子

int authenticators = BiometricManager.Authenticators.DEVICE_CREDENTIAL | BiometricManager.Authenticators.BIOMETRIC_WEAK;
Log.d(TAG, "set: authenticators:" + authenticators);
builder.setAllowedAuthenticators(authenticators);

当然为了兼容Q的行为,建议API判断兼容。

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {builder.setDeviceCredentialAllowed(true);
} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){int authenticators = BiometricManager.Authenticators.DEVICE_CREDENTIAL | BiometricManager.Authenticators.BIOMETRIC_WEAK;Log.d(TAG, "showLockScreen: authenticators:" + authenticators);builder.setAllowedAuthenticators(authenticators);
}

根据参数解释,可以是三个值当中任何一个或者多个的组合。

 A bit field representing all valid authenticator types that may be invoked by the prompt. Value is either 0 or a combination of BiometricManager.Authenticators.BIOMETRIC_STRONG, BiometricManager.Authenticators.BIOMETRIC_WEAK, and BiometricManager.Authenticators.DEVICE_CREDENTIAL.

真的是这样吗?

如果我单个单个的给,比如:BiometricManager.Authenticators.BIOMETRIC_WEAK。程序FC.

07-07 04:13:35.816 20008 20008 D activity1: click btn...
07-07 04:13:35.844 20008 20008 D activity1: top activity is dsfingerprint.dy.test.com.dsfingerprint.MainActivity
07-07 04:13:35.849 20008 20008 D activity1: showLockScreen: authenticators:255
07-07 04:13:35.850 20008 20008 D AndroidRuntime: Shutting down VM
07-07 04:13:35.855 20008 20008 E AndroidRuntime: FATAL EXCEPTION: main
07-07 04:13:35.855 20008 20008 E AndroidRuntime: Process: com.dsfingerprint, PID: 20008
07-07 04:13:35.855 20008 20008 E AndroidRuntime: java.lang.IllegalStateException: Could not execute method for android:onClick
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.view.View.performClick(View.java:7455)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.view.View.performClickInternal(View.java:7428)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.view.View.access$3600(View.java:813)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.view.View$PerformClick.run(View.java:28480)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:938)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:223)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7736)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:621)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	... 11 more
07-07 04:13:35.855 20008 20008 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Negative text must be set and non-empty
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at android.hardware.biometrics.BiometricPrompt$Builder.build(BiometricPrompt.java:432)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at dsfingerprint.dy.test.com.dsfingerprint.MainActivity.showLockScreen(MainActivity.java:603)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	at dsfingerprint.dy.test.com.dsfingerprint.MainActivity.onRemoveBtnClick(MainActivity.java:429)
07-07 04:13:35.855 20008 20008 E AndroidRuntime: 	... 13 more

看看BiometricPrompt源码。

AndroidR/frameworks/base/core/java/android/hardware/biometrics/BiometricPrompt.java

AndroidR/frameworks/base/core/java/android/hardware/biometrics/BiometricPrompt.java/*** Creates a {@link BiometricPrompt}.** @return An instance of {@link BiometricPrompt}.** @throws IllegalArgumentException If any required fields are unset, or if given any* invalid combination of field values.*/@NonNullpublic BiometricPrompt build() {final CharSequence title = mBundle.getCharSequence(KEY_TITLE);final CharSequence negative = mBundle.getCharSequence(KEY_NEGATIVE_TEXT);final boolean useDefaultTitle = mBundle.getBoolean(KEY_USE_DEFAULT_TITLE, false);final boolean deviceCredentialAllowed = mBundle.getBoolean(KEY_ALLOW_DEVICE_CREDENTIAL);final @Authenticators.Types int authenticators =mBundle.getInt(KEY_AUTHENTICATORS_ALLOWED, 0);final boolean willShowDeviceCredentialButton = deviceCredentialAllowed|| (authenticators & Authenticators.DEVICE_CREDENTIAL) != 0;if (TextUtils.isEmpty(title) && !useDefaultTitle) {throw new IllegalArgumentException("Title must be set and non-empty");} else if (TextUtils.isEmpty(negative) && !willShowDeviceCredentialButton) {//本条件请注意throw new IllegalArgumentException("Negative text must be set and non-empty");} else if (!TextUtils.isEmpty(negative) && willShowDeviceCredentialButton) {throw new IllegalArgumentException("Can't have both negative button behavior"+ " and device credential enabled");}return new BiometricPrompt(mContext, mBundle, mPositiveButtonInfo, mNegativeButtonInfo);}}

抛出异常的条件判断中,只跟两个输入有关一个就是authenticators,另一个是@Deprecated API setDeviceCredentialAllowed()。

  /* @deprecated Replaced by {@link #setAllowedAuthenticators(int)}.*/@Deprecated@NonNullpublic Builder setDeviceCredentialAllowed(boolean allowed) {mBundle.putBoolean(KEY_ALLOW_DEVICE_CREDENTIAL, allowed);return this;}

如果想不用过时API setDeviceCredentialAllowed(),这个传入的参数authenticators很重要,最起码是BiometricManager.Authenticators.DEVICE_CREDENTIAL或者它和其它另外两个的结合。

讲了这么多,先来看看,这个三个authenticators可能值是多少。

public interface Authenticators {int EMPTY_SET = 0x0000;int BIOMETRIC_MAX_STRENGTH = 0x0001;int BIOMETRIC_STRONG = 0x000F;int BIOMETRIC_WEAK = 0x00FF;int BIOMETRIC_CONVENIENCE = 0x0FFF;int BIOMETRIC_MIN_STRENGTH = 0x7FFF;int DEVICE_CREDENTIAL = 1 << 15;
}

两个byte的bit位就这么分掉了,不过只有上述API文档提到的三个才开放给到普通应用使用,其它平台内部使用。
基于上述代码追溯,所以直接给0 也是不可以的。程序会发生异常.

07-07 04:32:16.903 16143 16143 D activity1: onResume: 
07-07 04:32:18.515 16143 16143 D activity1: click btn...
07-07 04:32:18.525 16143 16143 D activity1: top activity is dsfingerprint.dy.test.com.dsfingerprint.MainActivity
07-07 04:32:18.531 16143 16143 D activity1: showLockScreen: authenticators:0
07-07 04:32:18.532 16143 16143 D AndroidRuntime: Shutting down VM
07-07 04:32:18.537 16143 16143 E AndroidRuntime: FATAL EXCEPTION: main
07-07 04:32:18.537 16143 16143 E AndroidRuntime: Process: com.dsfingerprint, PID: 16143
07-07 04:32:18.537 16143 16143 E AndroidRuntime: java.lang.IllegalStateException: Could not execute method for android:onClick
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.view.View.performClick(View.java:7455)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.view.View.performClickInternal(View.java:7428)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.view.View.access$3600(View.java:813)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.view.View$PerformClick.run(View.java:28480)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:938)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:223)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7736)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:621)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	... 11 more
07-07 04:32:18.537 16143 16143 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Negative text must be set and non-empty
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at android.hardware.biometrics.BiometricPrompt$Builder.build(BiometricPrompt.java:432)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at dsfingerprint.dy.test.com.dsfingerprint.MainActivity.showLockScreen(MainActivity.java:603)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	at dsfingerprint.dy.test.com.dsfingerprint.MainActivity.onRemoveBtnClick(MainActivity.java:429)
07-07 04:32:18.537 16143 16143 E AndroidRuntime: 	... 13 more

除非结合过时的API setDeviceCredentialAllowed(true)。

但是如此一来,申请BiometricPrompt变得无意义了。

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {builder.setDeviceCredentialAllowed(true);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {builder.setDeviceCredentialAllowed(true);int authenticators = 0;//BiometricManager.Authenticators.DEVICE_CREDENTIAL | BiometricManager.Authenticators.BIOMETRIC_WEAK;Log.d(TAG, "showLockScreen: authenticators:" + authenticators);builder.setAllowedAuthenticators(authenticators);
}final BiometricPrompt bp = builder.build();
bp.authenticate(mCancelSig,runnable -> {Log.d(TAG, "showLockScreen: xxx");},authenticationCallback);

log:

07-07 04:33:51.690 25788 25788 D activity1: click btn...
07-07 04:33:51.717 25788 25788 D activity1: top activity is dsfingerprint.dy.test.com.dsfingerprint.MainActivity
07-07 04:33:51.721 25788 25788 D activity1: showLockScreen: authenticators:0
07-07 04:33:51.729   807   807 E BiometricService: No authenticators requested
07-07 04:33:51.730 25788 25808 D activity1: showLockScreen: xxx

如果,直接使用@Deprecated API  setDeviceCredentialAllowed(true),他默认会找到BiometricManager.Authenticators.DEVICE_CREDENTIAL,如果只设置了密码(Pattern/PIN/password)的话。
效果等同builder.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL)。
但是如果还录入了指纹,跟Android Q表现没差。

如果密码也没设置呢?无意义。报BIOMETRIC_NOT_EROLLED(6),执行Executor runnable。

01-02 06:37:16.924  1783  1783 D activity1: click btn...
01-02 06:37:16.938  1783  1783 D activity1: top activity is dsfingerprint.dy.test.com.dsfingerprint.MainActivity
01-02 06:37:16.945   991   991 D BiometricService: Package: com.dsfingerprint Authenticator ID: 0 Modality: 2 Reported Modality: 2 Status: 6
01-02 06:37:16.947  1783  2094 D activity1: showLockScreen: xxx

回过来,直接使用推荐API只设置BiometricManager.Authenticators.DEVICE_CREDENTIAL,情况如何?
1)无密码,无指纹

报BIOMETRIC_INSUFFICIENT_STRENGTH(3)

01-02 06:42:04.071  4549  4549 D activity1: click btn...
01-02 06:42:04.079  4549  4549 D activity1: top activity is dsfingerprint.dy.test.com.dsfingerprint.MainActivity
01-02 06:42:04.083  4549  4549 D activity1: showLockScreen: authenticators:32768
01-02 06:42:04.093   991   991 D BiometricService: Package: com.dsfingerprint Authenticator ID: 0 Modality: 2 Reported Modality: 0 Status: 3
01-02 06:42:04.094  4549  4572 D activity1: showLockScreen: xxx

2)只设置密码,无指纹
报BIOMETRIC_INSUFFICIENT_STRENGTH(3),无论直接返回验证失败,还是验证pass,都直接执行Executor runnable,authenticationCallback无回调。

01-02 06:44:53.711  5689  5689 D activity1: click btn...
01-02 06:44:53.727  5689  5689 D activity1: top activity is dsfingerprint.dy.test.com.dsfingerprint.MainActivity
01-02 06:44:53.727  5689  5689 D activity1: showLockScreen: authenticators:32768
01-02 06:44:53.738   991   991 D BiometricService: Package: com.dsfingerprint Authenticator ID: 0 Modality: 2 Reported Modality: 0 Status: 3
01-02 06:44:53.738   991   991 D BiometricService: Creating auth session. Modality: 0, cookie: 37872452, authenticators: 32768
01-02 06:44:53.738   991   991 D BiometricService: New AuthSession, mSysUiSessionId: 1246244778
01-02 06:44:53.739  2405  2405 D BiometricPrompt/AuthController: showAuthenticationDialog, authenticators: 32768, biometricModality: 0, requireConfirmation: false, operationId: 0, sysUiSessionId: 1246244778
01-02 06:44:53.745  2405  2405 D BiometricPrompt/AuthController: userId: 0 savedState: null mCurrentDialog: null newDialog: com.android.systemui.biometrics.AuthContainerView{df74000 VFE...... .F....I. 0,0-0,0} type: 0 sysUiSessionId: 1246244778
01-02 06:44:53.786  6128  6128 D tctsidebar: TctSideBarService   :onChange listening package tag : 1 , com.android.systemui/BiometricPrompt
01-02 06:44:55.343   991  3109 D LockSettingsService: spBasedDoVerifyCredential: user=0 challengeType=0 hasEnrolledBiometrics=false
01-02 06:44:55.490  1150  1150 D keystore: AddAuthenticationToken: timestamp = 10985330, time_received = 3483
01-02 06:44:55.624  1150  1150 D keystore: AddAuthenticationToken: timestamp = 10985466, time_received = 3483
01-02 06:44:55.721  1150  1150 D keystore: AddAuthenticationToken: timestamp = 10985562, time_received = 3483
01-02 06:44:56.120  2405  2405 D BiometricPrompt/AuthContainerView: pendingCallback: 7 sysUISessionId: 1246244778
01-02 06:44:56.120  2405  2405 D BiometricPrompt/AuthController: onDialogDismissed: 7
01-02 06:44:56.121  2405  2405 D BiometricPrompt/AuthContainerView: Removing container, mSysUiSessionId: 1246244778
01-02 06:44:56.122  1150  1150 D keystore: AddAuthenticationToken: timestamp = 10985562, time_received = 3483
01-02 06:44:56.123   991   991 E BiometricService: mTokenEscrow is null
01-02 06:44:56.124  5689  5707 D activity1: showLockScreen: xxx

3)录入指纹,
报BIOMETRIC_INSUFFICIENT_STRENGTH(3), 只能弹出Pattern、PIN、Password验证界面,无法指纹验证, 执行Executor runnable, authenticationCallback无回调。

01-02 06:47:13.297  5689  5689 D activity1: click btn...
01-02 06:47:13.303  5689  5689 D activity1: top activity is dsfingerprint.dy.test.com.dsfingerprint.MainActivity
01-02 06:47:13.303  5689  5689 D activity1: showLockScreen: authenticators:32768
01-02 06:47:13.309   991   991 D BiometricService: Package: com.dsfingerprint Authenticator ID: 0 Modality: 2 Reported Modality: 0 Status: 3
01-02 06:47:13.309   991   991 D BiometricService: Creating auth session. Modality: 0, cookie: 1761879584, authenticators: 32768
01-02 06:47:13.309   991   991 D BiometricService: New AuthSession, mSysUiSessionId: -1877024172
01-02 06:47:13.310  2405  2405 D BiometricPrompt/AuthController: showAuthenticationDialog, authenticators: 32768, biometricModality: 0, requireConfirmation: false, operationId: 0, sysUiSessionId: -1877024172
01-02 06:47:13.315  2405  2405 D BiometricPrompt/AuthController: userId: 0 savedState: null mCurrentDialog: null newDialog: com.android.systemui.biometrics.AuthContainerView{df5e4fc VFE...... .F....I. 0,0-0,0} type: 0 sysUiSessionId: -1877024172
01-02 06:47:13.346  6128  6128 D tctsidebar: TctSideBarService   :onChange listening package tag : 1 , com.android.systemui/BiometricPrompt
01-02 06:47:13.766 10201 10733 W PlayCommon: [87] alsu.a(7): No account for auth token provided01-02 06:47:15.725   991  2850 D LockSettingsService: spBasedDoVerifyCredential: user=0 challengeType=0 hasEnrolledBiometrics=true
01-02 06:47:15.872  1150  1150 D keystore: AddAuthenticationToken: timestamp = 11125713, time_received = 3623
01-02 06:47:16.014  1150  1150 D keystore: AddAuthenticationToken: timestamp = 11125856, time_received = 3623
01-02 06:47:16.111  1150  1150 D keystore: AddAuthenticationToken: timestamp = 11125952, time_received = 3623
01-02 06:47:16.118   991   991 D FingerprintService: setActiveUser(0)
01-02 06:47:16.131  1434  1434 D talog   : V [gf_fpcore_common][gf_fpcore_get_authenticator_id] enter
01-02 06:47:16.131  1434  1434 D talog   : V [gf_fpcore_common][gf_fpcore_get_authenticator_id] exit
01-02 06:47:16.138   991   991 W AlarmManager: Unrecognized alarm listener com.android.server.locksettings.LockSettingsStrongAuth$NonStrongBiometricIdleTimeoutAlarmListener@15dac89
01-02 06:47:16.504  2405  2405 D BiometricPrompt/AuthContainerView: pendingCallback: 7 sysUISessionId: -1877024172
01-02 06:47:16.505  2405  2405 D BiometricPrompt/AuthController: onDialogDismissed: 7
01-02 06:47:16.505  2405  2405 D BiometricPrompt/AuthContainerView: Removing container, mSysUiSessionId: -1877024172
01-02 06:47:16.507  1150  1150 D keystore: AddAuthenticationToken: timestamp = 11125952, time_received = 3624
01-02 06:47:16.508   991   991 E BiometricService: mTokenEscrow is null
01-02 06:47:16.509  5689  5707 D activity1: showLockScreen: xxx

4)设置BiometricManager.Authenticators.DEVICE_CREDENTIAL | BiometricManager.Authenticators.BIOMETRIC_WEAK
弹指纹验证窗口(如果有指纹),无指纹则直接弹密码验证弹框。


【小结】
Android R开始,@Deprecated API setDeviceCredentialAllowed(true)仍然有效,不会导致程序异常,不推荐使用。
API30推荐的替换API setAllowedAuthenticators(int)。
但是需要注意,传入参数必须至少有BiometricManager.Authenticators.DEVICE_CREDENTIAL,否则程序抛异常。
如果还想生物识别 指纹验证方式,最少需要需要传入:BiometricManager.Authenticators.DEVICE_CREDENTIAL | BiometricManager.Authenticators.BIOMETRIC_WEAK。


更正结论,

并非一定要申请DEVICE_CREDENTIAL, 如果单独申请BIOMETRIC_WEAK也不是不行,但是要同步配合多设置参数,比如:error log里边提示的, 原来默认左边negative button是跳转到验证设备密码界面,但是不申请密码了. 这样程序不知道该如何处理,需要自身指定该行为,比如取消验证之类的.

报错log:

06-15 20:37:02.809 22329 22329 D AndroidRuntime: Shutting down VM
06-15 20:37:02.810 22329 22329 E AndroidRuntime: FATAL EXCEPTION: main
06-15 20:37:02.810 22329 22329 E AndroidRuntime: Process: com.start.testdemo, PID: 22329
06-15 20:37:02.810 22329 22329 E AndroidRuntime: java.lang.IllegalArgumentException: Negative text must be set and non-empty
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at android.hardware.biometrics.BiometricPrompt$Builder.build(BiometricPrompt.java:483)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at com.start.testdemo.ui.activity.BiometricPromptActivity.startBPUI(BiometricPromptActivity.java:91)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at com.start.testdemo.ui.activity.BiometricPromptActivity.access$000(BiometricPromptActivity.java:26)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at com.start.testdemo.ui.activity.BiometricPromptActivity$2.run(BiometricPromptActivity.java:76)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:958)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at android.os.Looper.loopOnce(Looper.java:257)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:368)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:8826)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
06-15 20:37:02.810 22329 22329 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
06-15 20:37:02.842  1785  3983 W ActivityTaskManager:   Force finishing activity com.start.testdemo/.ui.activity.BiometricPromptActivity
06-15 20:37:02.844  1785  3983 D ActivityTaskManager: setVisibility(Token{3c646e1 ActivityRecord{970a2eb u0 com.start.testdemo/.ui.activity.BiometricPromptActivity t3712 f}}}, visible=false) defer commitVisibility for transition collecting

正确用法:

biometricPrompt = new BiometricPrompt.Builder(this).setTitle(getString(R.string.start_biometric_prompt_ui_title))//.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_WEAK | BiometricManager.Authenticators.DEVICE_CREDENTIAL).setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_WEAK).setNegativeButton(......).build();

正确输出的log如下:

06-15 20:54:57.006 25595 25595 D BPUIActivity: startBpUI: start BP UI
06-15 20:54:57.007 25595 25595 D BPUIActivity: startBpUI: Android API:34
06-15 20:54:57.012  1785  3190 E OplusCustomizeRestrictionManagerService: isBiometricDisabled start
06-15 20:54:57.013  1785  3190 E OplusCustomizeRestrictionManagerService: isBiometricDisabled start
06-15 20:54:57.015  1785  3190 E OplusCustomizeRestrictionManagerService: isBiometricDisabled start
06-15 20:54:57.015  1785  3190 D BiometricService/PreAuthInfo: Package: com.start.testdemo Sensor ID: 4 Modality: 8 Status: 1
06-15 20:54:57.015  1785  3190 E OplusCustomizeRestrictionManagerService: isBiometricDisabled start
06-15 20:54:57.015  1785  3190 D BiometricService/PreAuthInfo: Package: com.start.testdemo Sensor ID: 0 Modality: 2 Status: 7
06-15 20:54:57.015  1785  3190 D BiometricService/PreAuthInfo: getCanAuthenticateInternal Modality: 8 AuthenticatorStatus: 1
06-15 20:54:57.015  1785  3190 D BiometricService: handleAuthenticate: modality(8), status(0), preAuthInfo: BiometricRequested: true, StrengthRequested: 255, CredentialRequested: false, Eligible:{4 }, Ineligible:{ID(0), oemStrength: 15, updatedStrength: 15, modality 2, state: 4, cookie: 1593309045:7 }, CredentialAvailable: true,  requestId: 48 promptInfo.isIgnoreEnrollmentState: false
06-15 20:54:57.015  1785  3190 D BiometricService: Creating authSession with authRequest: BiometricRequested: true, StrengthRequested: 255, CredentialRequested: false, Eligible:{4 }, Ineligible:{ID(0), oemStrength: 15, updatedStrength: 15, modality 2, state: 4, cookie: 1593309045:7 }, CredentialAvailable: true, 
06-15 20:54:57.015  1785  3190 D BiometricService/AuthSession: Creating AuthSession with: BiometricRequested: true, StrengthRequested: 255, CredentialRequested: false, Eligible:{4 }, Ineligible:{ID(0), oemStrength: 15, updatedStrength: 15, modality 2, state: 4, cookie: 1593309045:7 }, CredentialAvailable: true, 
06-15 20:54:57.015  1785  3190 V BiometricService/AuthSession: set to unknown state sensor: 4
06-15 20:54:57.016  1785  3190 V BiometricService/AuthSession: waiting for cooking for sensor: 4
06-15 20:54:57.018  1785  3190 D UaBiometricScheduler/FaceProvider/default/4: [Added] {[1259] com.android.server.biometrics.sensors.face.aidl.FaceAuthenticationClient, proto=3, owner=com.start.testdemo, cookie=1667886681, requestId=48, userId=0}, new queue size: 1
06-15 20:54:57.379  1785  3190 D BiometricService: handleOnDialogAnimatedIn
06-15 20:54:57.398  3378  3378 V OplusAuthBiometricView: newState: 2
06-15 20:54:57.398  3378  3378 V OplusAuthBiometricView: isDeviceCredentialAllowed=: false
06-15 20:54:57.398  3378  3378 V OplusAuthBiometricView: mRequireConfirmation=: true
06-15 20:54:57.420  2311 27850 E face_aidl.ImageReaderHelper: wake verify thread
06-15 20:54:57.421  2311  3216 I face_aidl.AlgoEngine: startAuthenticate, authType =0

这才符合三方APP的使用需要, 公司APP不可能把鉴权验证交给设备密码.

这篇关于BiometricPrompt.Builder.setDeviceCredentialAllowed(boolean)方法过时了,怎么破。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1141574

相关文章

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态

Java中的String.valueOf()和toString()方法区别小结

《Java中的String.valueOf()和toString()方法区别小结》字符串操作是开发者日常编程任务中不可或缺的一部分,转换为字符串是一种常见需求,其中最常见的就是String.value... 目录String.valueOf()方法方法定义方法实现使用示例使用场景toString()方法方法

Java中List的contains()方法的使用小结

《Java中List的contains()方法的使用小结》List的contains()方法用于检查列表中是否包含指定的元素,借助equals()方法进行判断,下面就来介绍Java中List的c... 目录详细展开1. 方法签名2. 工作原理3. 使用示例4. 注意事项总结结论:List 的 contain

macOS无效Launchpad图标轻松删除的4 种实用方法

《macOS无效Launchpad图标轻松删除的4种实用方法》mac中不在appstore上下载的应用经常在删除后它的图标还残留在launchpad中,并且长按图标也不会出现删除符号,下面解决这个问... 在 MACOS 上,Launchpad(也就是「启动台」)是一个便捷的 App 启动工具。但有时候,应

SpringBoot日志配置SLF4J和Logback的方法实现

《SpringBoot日志配置SLF4J和Logback的方法实现》日志记录是不可或缺的一部分,本文主要介绍了SpringBoot日志配置SLF4J和Logback的方法实现,文中通过示例代码介绍的非... 目录一、前言二、案例一:初识日志三、案例二:使用Lombok输出日志四、案例三:配置Logback一

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

mysql出现ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost‘ (10061)的解决方法

《mysql出现ERROR2003(HY000):Can‘tconnecttoMySQLserveron‘localhost‘(10061)的解决方法》本文主要介绍了mysql出现... 目录前言:第一步:第二步:第三步:总结:前言:当你想通过命令窗口想打开mysql时候发现提http://www.cpp

Mysql删除几亿条数据表中的部分数据的方法实现

《Mysql删除几亿条数据表中的部分数据的方法实现》在MySQL中删除一个大表中的数据时,需要特别注意操作的性能和对系统的影响,本文主要介绍了Mysql删除几亿条数据表中的部分数据的方法实现,具有一定... 目录1、需求2、方案1. 使用 DELETE 语句分批删除2. 使用 INPLACE ALTER T

MySQL INSERT语句实现当记录不存在时插入的几种方法

《MySQLINSERT语句实现当记录不存在时插入的几种方法》MySQL的INSERT语句是用于向数据库表中插入新记录的关键命令,下面:本文主要介绍MySQLINSERT语句实现当记录不存在时... 目录使用 INSERT IGNORE使用 ON DUPLICATE KEY UPDATE使用 REPLACE