【问题标题】:Is it possible to ask user if he wants to update google play services or not?是否可以询问用户是否要更新 google play 服务?
【发布时间】:2015-06-20 18:58:04
【问题描述】:

在他们为谷歌播放服务提供的示例中,他们处理可能的版本更新,如下所示:

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(from);
        if (resultCode != ConnectionResult.SUCCESS) {
            if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
                GooglePlayServicesUtil.getErrorDialog(resultCode, context,
                        PLAY_SERVICES_RESOLUTION_REQUEST).show();
            } else {
                error(TAG, "this device is not supported");
            }

这会产生类似

的消息

“如果您不更新 Google 服务,您的应用程序将无法运行”。

对于我的应用程序来说,这个说法太强了,因为我只使用服务来提供一些可选功能。

我可以用我自己的对话框替换GooglePlayServicesUtil.getErrorDialog() 对话框吗?

理想情况下,我想拥有类似的东西

“需要 Google 服务更新。是/否”

【问题讨论】:

  • AFAIK 您不必显示 Play Services 错误对话框,但如果您显示自己的错误对话框,则您只能靠自己以某种方式引导用户通过 Play 商店更新 Play 服务。我不知道这是否有正式记录。
  • 我目前没有显示更新对话框,不。但是,这种方式用户不知道他可以更新并获得更多功能。我认为 Google Play 对话框消息有点误导,我的应用程序没有停止工作,他们怎么知道它会停止工作?
  • "我的应用程序没有停止工作,他们怎么知道它会停止工作?" -- 它们基于您正在编译的 Play Services SDK。您的清单中有一个 <meta-data> 元素(手动添加或可能通过清单合并),提供有关您正在使用的 SDK 的信息。反过来,这会驱动所需的最低 Play 服务安装,如果设备正在摇摆旧安装(或完全缺少 Play 服务),这反过来会驱动错误对话框。
  • 你不能只检查结果,如果是ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED,请询问用户是否要更新。如果是,请调用 GooglePlayServicesUtil.getErrorDialog(result, ...)。
  • “我是否因为不进行更新而遗漏了任何潜在的危险?” -- 只要您在用户尚未更新的情况下实际上并未使用 Play 服务,就应该没有风险。

标签: android google-cloud-messaging


【解决方案1】:

你可以这样做:

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(from);
            if (resultCode != ConnectionResult.SUCCESS) {

            // show your own AlertDialog for example:
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            // set the message
            builder.setMessage("This app use google play services only for optional features")
            .setTitle("Do you want to update?"); // set a title

            builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                    // User clicked OK button

                    final String appPackageName = "com.google.android.gms";
                    try {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
                    }catch (android.content.ActivityNotFoundException anfe) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
                    }
            }
       });
            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
               // User cancelled the dialog
           }
       });
    AlertDialog dialog = builder.create();

}

【讨论】:

猜你喜欢
  • 2013-12-24
  • 2018-01-12
  • 2014-05-30
  • 1970-01-01
  • 2021-05-13
  • 2014-01-06
  • 1970-01-01
  • 1970-01-01
  • 2014-02-15
相关资源
最近更新 更多