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

相关文章

Window Server2016加入AD域的方法步骤

《WindowServer2016加入AD域的方法步骤》:本文主要介绍WindowServer2016加入AD域的方法步骤,包括配置DNS、检测ping通、更改计算机域、输入账号密码、重启服务... 目录一、 准备条件二、配置ServerB加入ServerA的AD域(test.ly)三、查看加入AD域后的变

Window Server2016 AD域的创建的方法步骤

《WindowServer2016AD域的创建的方法步骤》本文主要介绍了WindowServer2016AD域的创建的方法步骤,文中通过图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录一、准备条件二、在ServerA服务器中常见AD域管理器:三、创建AD域,域地址为“test.ly”

NFS实现多服务器文件的共享的方法步骤

《NFS实现多服务器文件的共享的方法步骤》NFS允许网络中的计算机之间共享资源,客户端可以透明地读写远端NFS服务器上的文件,本文就来介绍一下NFS实现多服务器文件的共享的方法步骤,感兴趣的可以了解一... 目录一、简介二、部署1、准备1、服务端和客户端:安装nfs-utils2、服务端:创建共享目录3、服

Java 字符数组转字符串的常用方法

《Java字符数组转字符串的常用方法》文章总结了在Java中将字符数组转换为字符串的几种常用方法,包括使用String构造函数、String.valueOf()方法、StringBuilder以及A... 目录1. 使用String构造函数1.1 基本转换方法1.2 注意事项2. 使用String.valu

Python中使用defaultdict和Counter的方法

《Python中使用defaultdict和Counter的方法》本文深入探讨了Python中的两个强大工具——defaultdict和Counter,并详细介绍了它们的工作原理、应用场景以及在实际编... 目录引言defaultdict的深入应用什么是defaultdictdefaultdict的工作原理

使用Python进行文件读写操作的基本方法

《使用Python进行文件读写操作的基本方法》今天的内容来介绍Python中进行文件读写操作的方法,这在学习Python时是必不可少的技术点,希望可以帮助到正在学习python的小伙伴,以下是Pyth... 目录一、文件读取:二、文件写入:三、文件追加:四、文件读写的二进制模式:五、使用 json 模块读写

Oracle数据库使用 listagg去重删除重复数据的方法汇总

《Oracle数据库使用listagg去重删除重复数据的方法汇总》文章介绍了在Oracle数据库中使用LISTAGG和XMLAGG函数进行字符串聚合并去重的方法,包括去重聚合、使用XML解析和CLO... 目录案例表第一种:使用wm_concat() + distinct去重聚合第二种:使用listagg,

怎么关闭Ubuntu无人值守升级? Ubuntu禁止自动更新的技巧

《怎么关闭Ubuntu无人值守升级?Ubuntu禁止自动更新的技巧》UbuntuLinux系统禁止自动更新的时候,提示“无人值守升级在关机期间,请不要关闭计算机进程”,该怎么解决这个问题?详细请看... 本教程教你如何处理无人值守的升级,即 Ubuntu linux 的自动系统更新。来源:https://

Java后端接口中提取请求头中的Cookie和Token的方法

《Java后端接口中提取请求头中的Cookie和Token的方法》在现代Web开发中,HTTP请求头(Header)是客户端与服务器之间传递信息的重要方式之一,本文将详细介绍如何在Java后端(以Sp... 目录引言1. 背景1.1 什么是 HTTP 请求头?1.2 为什么需要提取请求头?2. 使用 Spr

Java如何通过反射机制获取数据类对象的属性及方法

《Java如何通过反射机制获取数据类对象的属性及方法》文章介绍了如何使用Java反射机制获取类对象的所有属性及其对应的get、set方法,以及如何通过反射机制实现类对象的实例化,感兴趣的朋友跟随小编一... 目录一、通过反射机制获取类对象的所有属性以及相应的get、set方法1.遍历类对象的所有属性2.获取