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

相关文章

AI绘图怎么变现?想做点副业的小白必看!

在科技飞速发展的今天,AI绘图作为一种新兴技术,不仅改变了艺术创作的方式,也为创作者提供了多种变现途径。本文将详细探讨几种常见的AI绘图变现方式,帮助创作者更好地利用这一技术实现经济收益。 更多实操教程和AI绘画工具,可以扫描下方,免费获取 定制服务:个性化的创意商机 个性化定制 AI绘图技术能够根据用户需求生成个性化的头像、壁纸、插画等作品。例如,姓氏头像在电商平台上非常受欢迎,

W外链微信推广短连接怎么做?

制作微信推广链接的难点分析 一、内容创作难度 制作微信推广链接时,首先需要创作有吸引力的内容。这不仅要求内容本身有趣、有价值,还要能够激起人们的分享欲望。对于许多企业和个人来说,尤其是那些缺乏创意和写作能力的人来说,这是制作微信推广链接的一大难点。 二、精准定位难度 微信用户群体庞大,不同用户的需求和兴趣各异。因此,制作推广链接时需要精准定位目标受众,以便更有效地吸引他们点击并分享链接

电脑桌面文件删除了怎么找回来?别急,快速恢复攻略在此

在日常使用电脑的过程中,我们经常会遇到这样的情况:一不小心,桌面上的某个重要文件被删除了。这时,大多数人可能会感到惊慌失措,不知所措。 其实,不必过于担心,因为有很多方法可以帮助我们找回被删除的桌面文件。下面,就让我们一起来了解一下这些恢复桌面文件的方法吧。 一、使用撤销操作 如果我们刚刚删除了桌面上的文件,并且还没有进行其他操作,那么可以尝试使用撤销操作来恢复文件。在键盘上同时按下“C

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

浅谈主机加固,六种有效的主机加固方法

在数字化时代,数据的价值不言而喻,但随之而来的安全威胁也日益严峻。从勒索病毒到内部泄露,企业的数据安全面临着前所未有的挑战。为了应对这些挑战,一种全新的主机加固解决方案应运而生。 MCK主机加固解决方案,采用先进的安全容器中间件技术,构建起一套内核级的纵深立体防护体系。这一体系突破了传统安全防护的局限,即使在管理员权限被恶意利用的情况下,也能确保服务器的安全稳定运行。 普适主机加固措施:

webm怎么转换成mp4?这几种方法超多人在用!

webm怎么转换成mp4?WebM作为一种新兴的视频编码格式,近年来逐渐进入大众视野,其背后承载着诸多优势,但同时也伴随着不容忽视的局限性,首要挑战在于其兼容性边界,尽管WebM已广泛适应于众多网站与软件平台,但在特定应用环境或老旧设备上,其兼容难题依旧凸显,为用户体验带来不便,再者,WebM格式的非普适性也体现在编辑流程上,由于它并非行业内的通用标准,编辑过程中可能会遭遇格式不兼容的障碍,导致操

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

【北交大信息所AI-Max2】使用方法

BJTU信息所集群AI_MAX2使用方法 使用的前提是预约到相应的算力卡,拥有登录权限的账号密码,一般为导师组共用一个。 有浏览器、ssh工具就可以。 1.新建集群Terminal 浏览器登陆10.126.62.75 (如果是1集群把75改成66) 交互式开发 执行器选Terminal 密码随便设一个(需记住) 工作空间:私有数据、全部文件 加速器选GeForce_RTX_2080_Ti

怎么让1台电脑共享给7人同时流畅设计

在当今的创意设计与数字内容生产领域,图形工作站以其强大的计算能力、专业的图形处理能力和稳定的系统性能,成为了众多设计师、动画师、视频编辑师等创意工作者的必备工具。 设计团队面临资源有限,比如只有一台高性能电脑时,如何高效地让七人同时流畅地进行设计工作,便成为了一个亟待解决的问题。 一、硬件升级与配置 1.高性能处理器(CPU):选择多核、高线程的处理器,例如Intel的至强系列或AMD的Ry

【VUE】跨域问题的概念,以及解决方法。

目录 1.跨域概念 2.解决方法 2.1 配置网络请求代理 2.2 使用@CrossOrigin 注解 2.3 通过配置文件实现跨域 2.4 添加 CorsWebFilter 来解决跨域问题 1.跨域概念 跨域问题是由于浏览器实施了同源策略,该策略要求请求的域名、协议和端口必须与提供资源的服务相同。如果不相同,则需要服务器显式地允许这种跨域请求。一般在springbo