3

In the example they have for google play services they handle possible version update like this:

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

This results in a message something like

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

For my application this statement is too strong, as I only use the services to provide for some oprional functionality.

Can I somehow replace the GooglePlayServicesUtil.getErrorDialog() dialog with my own one?

Ideally I would like to have something like

"Google Services update is desirable. Yes/No"

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
  • AFAIK you don't have to show the Play Services error dialog, but if you show your own, you are on your own to somehow lead the user over the Play Store to update Play Services. I don't know if that's formally documented. – CommonsWare Jun 20 '15 at 19:06
  • I'm not currently showing the update dialog, no. However, this way user is unaware that he can update and get more functionality. I think the Google Play dialog message is a bit misleading, my app doesn't stop working, how do they know it does? – Alexander Kulyakhtin Jun 20 '15 at 19:10
  • 1
    "my app doesn't stop working, how do they know it does?" -- they based on the Play Services SDK that you are compiling against. There's a `` element in your manifest (manually added or possibly through manifest merger) that provides info on the SDK you're using. That, in turn, drives the minimum required Play Services installation, which in turn drives the error dialog if the device is rocking an older installation (or lacks Play Services entirely). – CommonsWare Jun 20 '15 at 19:13
  • Can't you just check the result and if it is `ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED`, ask the user if he wants to update. If yes, call GooglePlayServicesUtil.getErrorDialog(result, ...). – marco Jun 20 '15 at 19:14
  • @marco This will be 2 dialogs: first mine then Google's – Alexander Kulyakhtin Jun 20 '15 at 19:15
  • @Alex: I know, but I cannot think about something better than that. – marco Jun 20 '15 at 19:16
  • @CommonsWare But it doesn't "stop working". When I see the installed play services are older than needed I remember that and do not use them at all then. Am I missing any potential dangers by not doing the update? – Alexander Kulyakhtin Jun 20 '15 at 19:17
  • 1
    "Am I missing any potential dangers by not doing the update?" -- so long as you're not actually using Play Services if the user hasn't updated, there should be no risk. – CommonsWare Jun 20 '15 at 19:24

1 Answers1

7

you could do something like this:

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

}
Clayton Oliveira
  • 625
  • 1
  • 6
  • 15
  • 1
    @Alex use a intent to redirect to google play services directly, see this question: http://stackoverflow.com/questions/27032717/how-to-open-google-play-store-app-directly-without-chooser-intent – Clayton Oliveira Jun 20 '15 at 19:22