Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check for Google Play Services API availability? (specifically the GCM API)

I am trying to use GCM to do async communication between my app and a tiny backend Java server running on my personal computer. My problem is I can't figure out the cross-linked and contradictory reference pages for GCM and Google Play Services. I would love to use one of the old answers to this question, but the API and documentation got reworked in the last couple months and all the similar questions I find are from last year or older.

Google's guide for setting up Google Play Services says to ensure the required APIs are present using either:

  1. The GoogleApiClient class, which provides an example for using the Drive API (.addApi(Drive.API)), but there is no GoogleCloudMessaging.API that I can find, so that's not going to work.
  2. "Another approach is to use the isGooglePlayServicesAvailable() method." This links to the GooglePlayServicesUtil class, but nearly every method in this class is deprecated in favor of GoogleApiAvailability's non-static version, and I would understandably like to avoid using deprecated code wherever possible. The GoogleApiAvailability class also won't let me instantiate it.

So my questions are these: How can I ensure that a device has an updated version of Google Play Services? And is there a way to check whether the GCM API is available before I use it (or do I even need to do this if Google Play Services is updated)?

Additional info:
Min SDK 14
Target SDK 22

Apologies for not linking to some of the docs, darn reputation link limits.

like image 781
Gabe V Avatar asked Jun 03 '15 20:06

Gabe V


1 Answers

Thanks to Daniel Nugent for pointing out that I had missed the existence of GoogleApiAvailability.getInstance()!

like image 88
Gabe V Avatar answered Oct 31 '22 17:10

Gabe V