GoogleApiClient
can work in Activity
, Fragment
or Service
. It needs a Context
and you can get it by getApplicationContext()
, getActivity()
etc. Your Fragment/Activity
has to implement these two interfaces:
implements
ConnectionCallbacks, OnConnectionFailedListener
then you will find these methods:
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
You have to connect this API client using this mGoogleApiClient.connect();
and disconnect via mGoogleApiClient.disconnect()
Here is the documentation about Accessing Google APIs. Here is the description. And this thread has my Demo working code.