【问题标题】:onActivityResult is deprecated how do I send startResolutionForResultonActivityResult 已弃用如何发送 startResolutionForResult
【发布时间】:2021-03-25 21:28:29
【问题描述】:

所以我使用 gps 类来打开 gps,这是一个允许我们发送到 onActivityResult 的方法,但由于在 AndroidX 上已弃用并且仍然可用,因此 Android 团队推荐我们下一个:

强烈建议使用 AndroidX 中引入的 Activity Result API

我有以下代码,我尝试发送到 onActivityResult

val rae = e as ResolvableApiException
rae.startResolutionForResult(context,Constants.GPS_REQUEST)

如何使用新 API 处理相同的事情?

【问题讨论】:

标签: android gps androidx deprecated onactivityresult


【解决方案1】:

我在 Kotlin 中所做的是:

registerForActivityResult(StartIntentSenderForResult()) { result ->
    if (result.resultCode == RESULT_OK) {
        // Your logic
    }
}.launch(IntentSenderRequest.Builder(rae.resolution).build())

原答案:https://stackoverflow.com/a/65943223/4625681

【讨论】:

    【解决方案2】:

    Here 被描述为未弃用

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 2021-08-12
    • 2017-12-19
    • 2021-09-16
    • 2021-12-13
    相关资源
    最近更新 更多