Google Play services: How to handle devices that do not have Google Play?
Asked Answered
E

5

28

Google Play services is an Android library whose goal is to provide:

  • OAuth 2.0 authentication
  • Google+ sign-in
  • Google+ +1 button
  • various other goodies

If I were to use it (for instance because I want Google+ sign-in), what would happen to users whose device does not have Google Play? (Nook, Cyanogenmod, China Mobile, old devices, maybe Huawei?, etc)

QUESTION: Will my app become incompatible with such devices? Will it be displayed as compatible but then crash, or not work?
Is there a best practice to keep this in mind when using Google Play services?

Eellike answered 2/11, 2012 at 8:40 Comment(0)
E
30
GooglePlayServicesUtil.isGooglePlayServicesAvailable(android.content.Context)

is deprecated!

Use:

 GoogleApiAvailability api = GoogleApiAvailability.getInstance();
        int code = api.isGooglePlayServicesAvailable(activity);
        if (code == ConnectionResult.SUCCESS) {
           // Do Your Stuff Here
        } else {
           AlertDialog alertDialog =
                 new AlertDialog.Builder(activity, R.style.AppCompatAlertDialogStyle).setMessage(
                       "You need to download Google Play Services in order to use this part of the application")
                       .create();
           alertDialog.show();
        }
Endow answered 22/1, 2016 at 9:53 Comment(1)
No need to create your own dialog, use GoogleApiAvailability.getInstance().getErrorDialog(activity, code, 0).show();Melodize
F
26

If the feature from Google Play Services is essential for your app there would be no way to get your App working.

You can check if the services are enabled from within your app with GooglePlayServicesUtil.isGooglePlayServicesAvailable(android.content.Context)
which returns ConnectionResult.SUCCESS if Play Services is available.

You can now try to convince the user to install it (if possible) or disable the feature that is using the service.

As the Google Play Services is not a feature declared in the manifest your app should install fine on any device but may crash later on if you are using the APIs without checking if they are available.

You can try the behaviour with the emulator. Just create an AVD without the Google APIs and put your App on it.

Flitter answered 2/11, 2012 at 9:37 Comment(1)
This method has been moved and deprecated. See @Maxi's answer below for the new method: https://mcmap.net/q/489526/-google-play-services-how-to-handle-devices-that-do-not-have-google-playLorelle
A
1

As others stated, your code should ideally check for Google Mobile Services. If you don't, it will crash with a java.lang.RuntimeException wrapping android.content.ActivityNotFoundException because you'll be invoking a function on a non-existing activity.

Good apps don't crash but instead spam users with notifications in all the places they rely on on play services as other answers suggested. If possible send only a single notification to users instead of spamming them with the same notification in every place you rely on play services - or close the app after a dialog explaining why it's closing.

Better apps (e.g. Signal) contain alternative logic for handling things like notifications without making play services a hard requirement.

To which degree you can make your app work without play services is almost entirely up to your use case. If you use Firebase for instance it will be very hard to make your app work without GMS.

In most cases it's possible to avoid GMS, in some cases it's maybe not the best idea (e.g. allowing users to use arbitrary location on a dating app).

Try searching for alternatives before you lock yourself in though: OpenStreetMap will work on more devices than Google Maps, it's not as complete as Google Maps in some regions though (it's good enough for picking a delivery location though).

The recommendation that you use GMS comes from Google. I'd personally recommend you to support more devices, vendors and OSs if it doesn't require doubling your code base.

Anatol answered 2/8, 2022 at 16:38 Comment(0)
E
0

If you are somehow required to use Play Services, or if you maintain a legacy app that makes calls to Play Services, then I would recommend this strategy:

  1. On app start, check whether Play Services is available or not
  2. If not available, redirect Play Services calls to microG

microG is an open source implementation of Google Play Services.
It lacks many features, but is under active development. Many features are still stubs.

For location services, there is also LOST, a drop-in replacement for the Google Play services location APIs.

You app might not work perfectly, but at least it is better than crashing.

Of course, the best is to NOT use Google Play Services, from the start.

Eellike answered 21/5, 2014 at 7:5 Comment(0)
S
0

If your app uses GMS features like Google Sign-In or Firebase Cloud Messaging, it won't work well on the devices that don't have GMS. It's recommended that you use GMS if a device supports GMS; otherwise, use HMS (Huawei Mobile Services).

Please refer to the following links:

So you can use Google+ Sign-In on the devices where GMS is available; otherwise, use HUAWEI Account Sign-In.

Stlouis answered 15/5, 2020 at 7:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.