1. Checking for Google Play Services
As documented here you should always ensure that:
- The Google Play Services APK is present at all.
- That the correct version is installed.
Mostly you would perform those checks in the onResume()
method. The GooglePlayServiceUtils
has a method called isGooglePlayServicesAvailable(...)
that checks both if the Google Play Services are installed and that they are the correct version. It returns an int
error code that tells you roughly what's wrong:
@Override
public void onResume() {
super.onResume();
int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
switch(errorCode) {
case ConnectionResult.SUCCESS:
// Google Play Services installed and up to date
break;
case ConnectionResult.SERVICE_MISSING:
// Google Play services is missing on this device.
break;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
// The installed version of Google Play services is out of date.
break;
case ConnectionResult.SERVICE_DISABLED:
// The installed version of Google Play services has been disabled on this device.
break;
case ConnectionResult.SERVICE_INVALID:
// The version of the Google Play services installed on this device is not authentic.
break;
case ConnectionResult.DATE_INVALID:
// The device date is likely set incorrectly.
break;
}
}
You can use a method like showErrorDialogFragment(...)
of the GooglePlayServiceUtils
to show an appropriate error message:
int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
if(GooglePlayServiceUtil.showErrorDialogFragment(errorCode, getActivity(), REQUEST_CODE)) {
// Dialog was shown
} else {
// Dialog was not shown.
}
The dialog is only shown when the error code is something other than ConnectionResult.SUCCESS
.
You can find documentation for the GooglePlayServiceUtil
class here.
2. Fallback
Whether you need a fallback depends solely on your app and the market you are targeting. For example if you publish it to the Google Play Store - which I assume you do since you use Google Play Services - then you don't really need a fallback. Because for people to download your app they first need the Google Play Store, and if they have the Google Play Store than they have access to the Google Play Services. It's of course a whole different story if you want to publish it for Amazon devices, or in the Nokia Store, because devices that have those don't have the Google Play Store or Google Play Services. Also in markets like China there are hardly any Android devices with the Google Play Store or any Google Services, so essentially you have to decide if it is necessary for your app, but as I said if you publish it to the Google Play Store I wouldn't worry about it. The checks and also the error dialog I mentioned above should be more than enough to ensure that your app works well. The rollout of new versions of the Google Play Services APK is normally pretty quick. It might take a few days, but after that most devices have received the update. You also have to think about one thing: If you develop your app to require features of the current Google Play Services than you most likely won't run into any problems since almost all devices already have the current version, it would be rather difficult to find a device that is not up to date. You just have to be careful when you are quickly pushing out an update to your app that uses some new feature that has been introduced just a few days ago. In that case you might run into more problems.
But in the end you have to remember that this all depends on the country you release your app in and on the ecosystems you want to release your app for.
I hope I could answer your question and if you have any further questions feel free to ask!