4

We're experiencing the following behavior which doesn't seem to make sense: An attempt to connect an instance of GoogleApiClient succeeds and calling isConnected() in our instance of GoogleApiClient returns true even when it's clear that the client cannot be connected to the service.

In order to confirm this behavior I enabled Airplane Mode before starting the app and then I'm printing the value returned by isConnected() which equals true.

So now I'm confused. Is this the expected behavior or a bug? Is it reporting a successful connection because the API handles being offline transparently?

Juan Campa
  • 1,181
  • 2
  • 14
  • 20

1 Answers1

2

This isConnected() call has nothing to do with whether the device has connectivitiy, it explains whether you are connected to the Google Play services service on the device itself. There are a number of operations that can't be performed until you've connected to the service, but can be performed whether or not the user is online (e.g. writing Plus moments).

There is no call to determine if the user is connected to the internet because there are already well known ways to do that, and that connection is tenuous. Just because your user is connected when they start your activity doesn't mean they'll be connected in a couple minutes (or even seconds) when you're ready to make your call.

That being said, sometimes to make the connection to the service an internet connection is needed (particularly when authorizing your app).

Hounshell
  • 5,321
  • 4
  • 34
  • 51