2

我有一个应用程序,我要求用户通过KeyguardManager使用PIN在我的应用程序中进行身份验证。

重要的是我必须android:showOnLockScreen="true"在清单中进行我的活动,所以当设备被锁定并且我的活动正在显示时,我正在点击“登录”按钮,它调用showAuthenticationScreen(),我正在接收 RESULT_CANCELED我的onActivityResult().

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showAuthenticationScreen() {
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    if (keyguardManager == null) {
        return;
    }

    Intent kgIntent = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.nnl_kg_title), getKgPrompt());

    if (kgIntent != null) {
        startActivityForResult(kgIntent, KG_REQUEST_ID);
    }
}

我查看了系统日志,发现我从BiometricService消息"Canceling from CDC"中得到了这个错误。这是系统日志的一部分。

936   936 I ActivityTaskManager: START u0 {act=android.app.action.CONFIRM_DEVICE_CREDENTIAL_WITH_USER flg=0x8080000 pkg=com.android.settings cmp=com.android.settings/.password.ConfirmDeviceCredentialActivity$InternalActivity (has extras)} from
uid 1000
11-11 10:54:53.076   936   972 D ActivityTaskManager: Top Process State changed to PROCESS_STATE_TOP_SLEEPING
11-11 10:54:53.092   936  1032 W ProcessStats: Tracking association SourceState{2c15fa1 com.android.settings/1000 Top #565108} whose proc state 1 is better than process ProcessState{54a9784 com.google.android.gms.persistent/10029 pkg=com.google.android.gms} proc st
ate 2 (9 skipped)
11-11 10:54:53.126   936   936 D BiometricService: Creating auth session. Modality: 1, cookie: 1632337634
11-11 10:54:53.127   936   936 V FingerprintService: startAuthentication(com.android.settings)
11-11 10:54:53.128   936   936 V FingerprintService: Returning cookie: 1632337634
11-11 10:54:53.128   936   936 D BiometricService: Matched cookie: 1632337634, 0 remaining
11-11 10:54:53.128   936   936 V FingerprintService: starting client AuthenticationClientImpl(com.android.settings) cookie: 1632337634/1632337634
11-11 10:54:53.135   936   936 W FingerprintService: client com.android.settings is authenticating...
11-11 10:54:53.161   936   936 D BiometricService: Cancelling from CDC
11-11 10:54:53.162   936   936 V FingerprintService: Stopping client com.android.settings, fromClient: false
11-11 10:54:53.173   936   936 W FingerprintService: client com.android.settings is no longer authenticating
11-11 10:54:53.177   936  3056 D ActivityTaskManager: Top Process State changed to PROCESS_STATE_TOP
11-11 10:54:53.195   936   936 V FingerprintService: handleError(client=com.android.settings, error = 5)
11-11 10:54:53.195   936   936 V FingerprintService: Done with client: com.android.settings
11-11 10:54:53.196   936   936 D BiometricService: Error: 5 cookie: 1632337634
11-11 10:54:53.285   936  3041 I ActivityTaskManager: Activity reported stop, but no longer stopping: ActivityRecord{9b6d8b u0 com.natigbabayev.biometricprompt/.MainActivity t1936}

那么有什么解决方案吗?即使设备被锁定,我仍然可以要求用户使用 PIN 进行身份验证吗?提前谢谢你们。

4

1 回答 1

-1

您从未使用过此功能 - onActivityResult(int requestCode, int resultCode, Intent data)在您的当前活动中

它用于处理活动的返回值,该活动将结果代码返回到您所在的当前活动中。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == KG_REQUEST_ID){
        if(resultCode == Activity.RESULT_OK) {
            // Your Code if Authenticated Successfully.
        }
        if(resultCode == Activity.RESULT_CANCELED) {
            // Your Code If Canceled.
        }
    }
}
于 2021-02-15T05:13:39.890 回答