是否可以询问用户是否要更新 google 播放服务?

Is it possible to ask user if he wants to update google play services or not?

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

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");
            }

这会产生类似于

的消息

"Your application won't work if you don't update Google Services".

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

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

理想情况下,我想要

"Google Services update is desirable. Yes/No"

你可以这样做:

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();

}