gpt4 book ai didi

android - 如何获取新的 GoogleApiAvailability.getErrorDialog() 的请求代码?

转载 作者:行者123 更新时间:2023-11-29 16:46:25 27 4
gpt4 key购买 nike

我正在关注 this guide检查 GoogleApiAvailability,它需要我调用 getErrorDialog(int responseCode)

however, the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then the user needs to install an update. In this case, call the getErrorDialog() method and pass it the result error code.

该指南用于 getErrorDialog(int responseCode)但是this page (getErrorDialog 上的超链接)表示该方法已弃用

This method was deprecated. Use getErrorDialog(Activity, int, int) instead.

根据文档,第一个 int 是请求代码,第二个 int 是响应代码。我从 isGoogleApiAvailable(context) 获得了响应代码,但我不知道请求代码是什么以及如何获得它。

这是我的代码:

  // Ensure Google Play services framework is installed
int gAAResult = GoogleApiAvailability
.getInstance()
.isGooglePlayServicesAvailable(this);
if(gAAResult == ConnectionResult.SUCCESS){
Log.d(TAG, "Play services available");
} else {
GoogleApiAvailability
.getInstance()
.getErrorDialog(this, ? ,gAAResult);
}

将问号替换为实际请求代码的地方作为临时解决方案,我已将 0 传递给它。我没有没有播放服务的设备。在模拟器上,该应用程序显示一个对话框(没有我的代码)来更新播放服务。但是 FCM 文档建议对这个检查进行编码

最佳答案

第一个 int 是 connectionResult,由 isGooglePlayServicesAvailable(Context context) 方法返回。第二个是用于错误对话框的 requestCode

显示错误对话框后,您将在 Activity 的方法 onActivityResult(int requestCode, int result, Intent data) 中获得回调,其中包含结果和传递的请求代码。由于您可能会从一个执行后结果开始多个 Activity ,getErrorDialog(...) 方法会要求您传递一个请求代码作为操作的唯一标识符,以帮助您处理结果。

您实际上需要实现这一点,因为通用的 Play 服务错误对话框可能会帮助用户更新他/她手机上的 Play 服务,因此您会收到问题已实际解决的通知。如果您不那么幸运,情况也是如此。

关于android - 如何获取新的 GoogleApiAvailability.getErrorDialog() 的请求代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47891937/

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