1

I have sucessfull working android maps API v2, but then i tried to test if i dont have Google Play services, will app offer to install it.

So i uninstalled Google Play services and my application is crashing now. Its not offering to intall Google Play services like it does in Sample App. In LogCat its printing Google play services is missing and after NullPointerException. In sample app i didnt see any code that handles that, i guess its inculded in map library. Im using SupportMapFragment, however in sample app its also used.

How to make app offer install play services like its in sample app ?

kort.es
  • 479
  • 2
  • 7
  • 26

1 Answers1

5

You can use the GooglePlayServicesUtil class for that. Your code will look something like this:

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if (resultCode == ConnectionResult.SUCCESS) 
{
    // Google Play Services installed correctly, continue
} 
else if (resultCode == ConnectionResult.SERVICE_MISSING ||
         resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ||
         resultCode == ConnectionResult.SERVICE_DISABLED) 
{           
    // Google Play Services not installed / too old / disabled.
    // Show dialog to install or update
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1);
    dialog.show();
} 
else 
{
    // Something else went wrong, handle this yourself
}

The getErrorDialog method will show the dialog that directs the user to the Google Play Store to install or update Google Play Services.

Jaap van Hengstum
  • 4,494
  • 4
  • 30
  • 34