【问题标题】:keyguardManager.createConfirmDeviceCredentialIntent() returns RESULT_CANCELEDon Android QkeyguardManager.createConfirmDeviceCredentialIntent() 在 Android Q 上返回 RESULT_CANCELED
【发布时间】:2020-03-06 22:54:13
【问题描述】:

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

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

    @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 收到此错误消息,并显示消息“正在从 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 进行身份验证吗? 提前谢谢你们。

【问题讨论】:

  • 你有解决办法吗?
  • 不@JithishPN。

标签: android security biometrics keyguard keyguardlock


【解决方案1】:

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

用于处理activity的返回值,返回结果码到你所在的当前activity中。

@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.
        }
    }
}

【讨论】:

    猜你喜欢
    • 2016-02-12
    • 2019-12-10
    • 2017-01-27
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 2019-08-03
    相关资源
    最近更新 更多