use of com.google.android.gms.common.api.GoogleApiClient in project Android-ReactiveLocation by mcharmas.
the class BaseObservableOnSubscribe method subscribe.
@Override
public void subscribe(ObservableEmitter<T> emitter) throws Exception {
final GoogleApiClient apiClient = createApiClient(emitter);
try {
apiClient.connect();
} catch (Throwable ex) {
if (!emitter.isDisposed()) {
emitter.onError(ex);
}
}
emitter.setDisposable(Disposables.fromAction(new Action() {
@Override
public void run() throws Exception {
onDisposed(apiClient);
apiClient.disconnect();
}
}));
}
use of com.google.android.gms.common.api.GoogleApiClient in project androidApp by InspectorIncognito.
the class GoogleAccountLoader method load.
@Override
public void load(final CredentialsListener listener) {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(TranSappApplication.getAppContext().getString(R.string.server_client_id)).build();
final GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(TranSappApplication.getAppContext()).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
OptionalPendingResult<GoogleSignInResult> pendingResult = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (pendingResult.isDone()) {
loadDataFromSignInResult(pendingResult.get(), listener, mGoogleApiClient);
} else {
pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(@NonNull GoogleSignInResult result) {
if (result.isSuccess()) {
loadDataFromSignInResult(result, listener, mGoogleApiClient);
} else {
listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
}
}
}, 5000, TimeUnit.MILLISECONDS);
}
}
@Override
public void onConnectionSuspended(int i) {
listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
}
});
mGoogleApiClient.connect();
}
Aggregations