gpt4 book ai didi

java - 自动选择第一个手机号码 HintRequest android

转载 作者:行者123 更新时间:2023-12-01 18:30:01 27 4
gpt4 key购买 nike

我想从 HintRequest android 自动选择第一个电话号码。

有什么可行的解决办法吗?

是否有任何解决方案,用户在未选择至少一个手机号码的情况下无法关闭提示请求对话框?

check this screenshot

最佳答案

// Example From Kotlin

implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.3.0'
implementation 'com.google.android.gms:play-services-base:17.1.0'
implementation 'com.google.android.gms:play-services-identity:17.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'

// Class : AutoDetectMobileNo

class AutoDetectMobileNo internal constructor(context: Context) {
private var googleApiClient: GoogleApiClient? = null
private val context: Context
private val appCompatActivity: AppCompatActivity = context as AppCompatActivity
fun requestPhoneNoHint() {
googleApiClient = GoogleApiClient.Builder(context)
.enableAutoManage(
appCompatActivity
) { }
.addApi(Auth.CREDENTIALS_API)
.build()
val hintRequest = HintRequest.Builder()
.setHintPickerConfig(
CredentialPickerConfig.Builder()
.setShowCancelButton(true)
.build()
)
.setPhoneNumberIdentifierSupported(true)
.build()
val intent =
Auth.CredentialsApi.getHintPickerIntent(googleApiClient, hintRequest)
try {
appCompatActivity.startIntentSenderForResult(
intent.intentSender,
RC_HINT,
null,
0,
0,
0
)
} catch (e: Throwable) {
Log.e("PHONE_HINT", "Could not start hint picker Intent", e)
}
}

fun getPhoneNo(data: Intent): String {
val cred: Credential =
data.getParcelableExtra(Credential.EXTRA_KEY)!!
return cred.id
}

interface Callback

companion object {
const val RC_HINT = 1000
}

init {
this.context = appCompatActivity.applicationContext
}
}


// On Your Activity / Fragment

val autoDetectMobileNo = AutoDetectMobileNo(this)
autoDetectMobileNo!!.requestPhoneNoHint()

override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == AutoDetectMobileNo.RC_HINT) {
if (resultCode == Activity.RESULT_OK) {
val mPhoneNumber = autoDetectMobileNo!!.getPhoneNo(data)
}
}
}

关于java - 自动选择第一个手机号码 HintRequest android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60182058/

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