来自 non-activity/application 上下文的 confirmDeveiceCredentialIntent
confirmDeveiceCredentialIntent from non-activity/application context
正如我们所知,我们在 KeyguardManager
中有一个 api 用于通过用户的设备锁对用户进行身份验证。 api 是:confirmDeviceCredentialIntent。
这个 api 的文档说:
Get an intent to prompt the user to confirm credentials (pin, pattern or password) for the current user of the device. The caller is expected to launch this activity using startActivityForResult(Intent, int) and check for RESULT_OK if the user successfully completes the challenge.
现在,我的问题是,我想在非 activity 上下文中调用此流程。我在我的应用程序中使用了一个 kv 存储,其内容将由我存储在 android 密钥库中的密钥加密。因此,当我想从该商店获取任何价值时,我首先需要对用户进行身份验证,以便在返回之前获取我的密钥并解密内容。
第二件事是,作为那个 kv 商店的消费者,我不想知道商店的加密是如何完成的,因此我不应该自己调用确认凭证。我只想从商店中获取我的价值,并且商店(非 ui 组件)有责任在 required 时调用身份验证流程。
所以大多数情况下,我会使用全局应用程序上下文。并且此上下文不提供 startActivityForResult
api。
有没有其他方法可以让我从用户那里获得确认凭据操作的结果?
我最终使用了虚拟机 Activity。这个 activity 本身由应用程序上下文启动,然后它处理调用 confirmCredentials
结果的意图。
正如我们所知,我们在 KeyguardManager
中有一个 api 用于通过用户的设备锁对用户进行身份验证。 api 是:confirmDeviceCredentialIntent。
这个 api 的文档说:
Get an intent to prompt the user to confirm credentials (pin, pattern or password) for the current user of the device. The caller is expected to launch this activity using startActivityForResult(Intent, int) and check for RESULT_OK if the user successfully completes the challenge.
现在,我的问题是,我想在非 activity 上下文中调用此流程。我在我的应用程序中使用了一个 kv 存储,其内容将由我存储在 android 密钥库中的密钥加密。因此,当我想从该商店获取任何价值时,我首先需要对用户进行身份验证,以便在返回之前获取我的密钥并解密内容。
第二件事是,作为那个 kv 商店的消费者,我不想知道商店的加密是如何完成的,因此我不应该自己调用确认凭证。我只想从商店中获取我的价值,并且商店(非 ui 组件)有责任在 required 时调用身份验证流程。
所以大多数情况下,我会使用全局应用程序上下文。并且此上下文不提供 startActivityForResult
api。
有没有其他方法可以让我从用户那里获得确认凭据操作的结果?
我最终使用了虚拟机 Activity。这个 activity 本身由应用程序上下文启动,然后它处理调用 confirmCredentials
结果的意图。