gpt4 book ai didi

android - startIntentSenderForResult 已弃用 Android

转载 作者:行者123 更新时间:2023-12-04 23:46:41 25 4
gpt4 key购买 nike

代码 fragment :

private fun requestHint() {
val hintRequest = HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build()
val credentialsClient = Credentials.getClient(this)
val intent = credentialsClient.getHintPickerIntent(hintRequest)
try {
startIntentSenderForResult(
intent.intentSender,
CREDENTIAL_PICKER_REQUEST,
null, 0, 0, 0
)
} catch (e: IntentSender.SendIntentException) {
e.printStackTrace()
}
}
我试图解决这个问题,来自 documentation但我不明白
如果有人知道如何解决它,请帮助
谢谢

最佳答案

使用下面的代码 -

private fun showPhoneNumberSuggestion() {

val hintRequest = HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build()

val options = CredentialsOptions.Builder()
.forceEnableSaveDialog()
.build()

// Then pass the hint request object to
// credentialsClient.getHintPickerIntent()
// to get an intent to prompt the user to
// choose a phone number.

val credentialClient = Credentials.getClient(applicationContext, options)
val intent = credentialClient.getHintPickerIntent(hintRequest)
try {

val intentSenderRequest = IntentSenderRequest.Builder(intent.intentSender).build()
phonePickIntentResultLauncher.launch(intentSenderRequest)

} catch (e: IntentSender.SendIntentException) {
e.printStackTrace()
}
}
对于 ActivityResult,使用 -
private val phonePickIntentResultLauncher =
registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result ->
if (result != null) {
val intent = result.data
val credential = intent?.getParcelableExtra<Credential>(Credential.EXTRA_KEY)
binding.inputPhone.setText(credential?.id)
}
}
请记住,没有请求代码。
为每个特定任务使用不同的结果启动器。

关于android - startIntentSenderForResult 已弃用 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67983163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com