Can GoogleApiClient be used in Fragment or should it always be used in Control?
GoogleApiClient
can work in Activity
, Fragment
or Service
. It requires it Context
, and you can get it getApplicationContext()
, getActivity()
etc. Yours Fragment/Activity
should implement these two interfaces:
implements
ConnectionCallbacks, OnConnectionFailedListener
then you will find the following methods:
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
You need to connect this API client using this mGoogleApiClient.connect();
and disconnect viamGoogleApiClient.disconnect()
Here's the documentation for accessing Google APIs. Here's a description. And this thread has my working Demo code.
source to share