简体   繁体   中英

No need to manually check Google Play Services version anymore?

It's been a while since I worked with Google Play Services and I'm now implementing a feature that requires location tracking. After following a dated example that used GoogleApiClient , I found this post about the new Location APIs at Android Developers blog:

https://android-developers.googleblog.com/2017/06/reduce-friction-with-new-location-apis.html

FusedLocationProviderClient client =
    LocationServices.getFusedLocationProviderClient(this);

client.requestLocationUpdates(LocationRequest.create(), pendingIntent)
    .addOnCompleteListener(new OnCompleteListener() {
      @Override
      public void onComplete(@NonNull Task task) {
        Log.d("MainActivity", "Result: " + task.getResult());
      }
    });
}

What caught my attention was something written at the bottom of the post, saying:

The new API will automatically resolve certain connection failures for you, so you don't need to write code that for things like prompting the user to update Google Play services .

Since I've already written that piece of code using GoogleApiAvailabilty I'm curious if it's safe to just remove it and let the FusedLocationProviderClient take care of it?

I've tried to find another source to verify this but failed, not really satisfied with half a line at the bottom of a blog post, hence posting the question here.

Ok so I'll answer my own question after a quick test. I temporarily removed the checks that made sure Google Play Services was available and the correct version. Then installed the app on an emulator without Google Play Services and when I try to use the LocationServices API I get a sticky headsup notification saying:

[app name] won't run unless you update Google Play Services.

So I guess it's safe to remove the checks.

Worth noting is that it seems the listeners (Success/Failure/Complete) are not called unless the user actually interacts with the notification, if they for example just press something else in your apps UI, the listeners were not called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM