com.google.android.gms.common.api.GoogleApiClient Java Examples
The following examples show how to use
com.google.android.gms.common.api.GoogleApiClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleApiHelper.java From social-app-android with Apache License 2.0 | 6 votes |
public static GoogleApiClient createGoogleApiClient(FragmentActivity fragmentActivity) { GoogleApiClient.OnConnectionFailedListener failedListener; if (fragmentActivity instanceof GoogleApiClient.OnConnectionFailedListener) { failedListener = (GoogleApiClient.OnConnectionFailedListener) fragmentActivity; } else { throw new IllegalArgumentException(fragmentActivity.getClass().getSimpleName() + " should implement OnConnectionFailedListener"); } GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(fragmentActivity.getResources().getString(R.string.google_web_client_id)) .requestEmail() .build(); return new GoogleApiClient.Builder(fragmentActivity) .enableAutoManage(fragmentActivity, failedListener) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); }
Example #2
Source File: MainActivity.java From android-Geofencing with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Rather than displayng this activity, simply display a toast indicating that the geofence // service is being created. This should happen in less than a second. if (!isGooglePlayServicesAvailable()) { Log.e(TAG, "Google Play services unavailable."); finish(); return; } mApiClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mApiClient.connect(); // Instantiate a new geofence storage area. mGeofenceStorage = new SimpleGeofenceStore(this); // Instantiate the current List of geofences. mGeofenceList = new ArrayList<Geofence>(); createGeofences(); }
Example #3
Source File: UtilityService.java From io2015-codelabs with Apache License 2.0 | 6 votes |
/** * Add geofences using Play Services */ private void addGeofencesInternal() { Log.v(TAG, ACTION_ADD_GEOFENCES); GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (connectionResult.isSuccess() && googleApiClient.isConnected()) { PendingIntent pendingIntent = PendingIntent.getBroadcast( this, 0, new Intent(this, UtilityReceiver.class), 0); GeofencingApi.addGeofences(googleApiClient, TouristAttractions.getGeofenceList(), pendingIntent); googleApiClient.disconnect(); } else { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); } }
Example #4
Source File: QuizReportActionService.java From android-Quiz with Apache License 2.0 | 6 votes |
@Override public void onHandleIntent(Intent intent) { if (intent.getAction().equals(ACTION_RESET_QUIZ)) { final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult result = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); if (!result.isSuccess()) { Log.e(TAG, "QuizReportActionService failed to connect to GoogleApiClient."); return; } CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi .getCapability(googleApiClient, RESET_QUIZ_CAPABILITY_NAME, CapabilityApi.FILTER_REACHABLE) .await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS); if (capabilityResult.getStatus().isSuccess()) { sendResetMessage(googleApiClient, capabilityResult.getCapability()); } else { Log.e(TAG, "Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage()); } } }
Example #5
Source File: GoogleDriveClient.java From financisto with GNU General Public License v2.0 | 6 votes |
private ConnectionResult connect() throws ImportExportException { if (googleApiClient == null) { String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context); if (googleDriveAccount == null) { throw new ImportExportException(R.string.google_drive_account_required); } googleApiClient = new GoogleApiClient.Builder(context) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .setAccountName(googleDriveAccount) //.addConnectionCallbacks(this) //.addOnConnectionFailedListener(this) .build(); } return googleApiClient.blockingConnect(1, TimeUnit.MINUTES); }
Example #6
Source File: EasyFirebaseAuth.java From EasyFirebase with Apache License 2.0 | 6 votes |
public EasyFirebaseAuth(GoogleApiClient googleApiClient) { mAuth = FirebaseAuth.getInstance(); this.googleApiClient = googleApiClient; mAuthListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { final FirebaseUser user = firebaseAuth.getCurrentUser(); if (user != null) { if (firebaseUserSubscriber != null) { firebaseUserSubscriber.onNext(new Pair<GoogleSignInAccount, FirebaseUser>(googleSignInAccount, user)); firebaseUserSubscriber.onCompleted(); } if (loggedSubcriber != null) { loggedSubcriber.onNext(user); } // User is signed in Log.d("TAG", "onAuthStateChanged:signed_in:" + user.getUid()); } else { // User is signed out Log.d("TAG", "onAuthStateChanged:signed_out"); } } }; }
Example #7
Source File: BaseActivity.java From attendee-checkin with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Google+ Sign in mApiClient = new GoogleApiClient.Builder(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN) .addScope(Plus.SCOPE_PLUS_PROFILE) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mConnectionProgressDialog = new ProgressDialog(this); mConnectionProgressDialog.setMessage(getString(R.string.signing_in)); GutenbergApplication app = GutenbergApplication.from(this); if (!app.isUserLoggedIn()) { selectAccount(false); } else { app.requestSync(false); } adjustTaskDescription(); }
Example #8
Source File: LocatrFragment.java From AndroidProgramming3e with Apache License 2.0 | 6 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); mClient = new GoogleApiClient.Builder(getActivity()).addApi(LocationServices.API) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(@Nullable Bundle bundle) { getActivity().invalidateOptionsMenu(); } @Override public void onConnectionSuspended(int i) { } }) .build(); }
Example #9
Source File: DeviceClient.java From wearabird with MIT License | 6 votes |
public void sendSensorData(final int sensorType, final int accuracy, final long timestamp, final float[] values) { ConnectionManager.getInstance(context).sendMessage(new ConnectionManager.ConnectionManagerRunnable(context) { @Override public void send(GoogleApiClient googleApiClient) { PutDataMapRequest dataMap = PutDataMapRequest.create("/sensors/" + sensorType); dataMap.getDataMap().putInt(DataMapKeys.ACCURACY, accuracy); dataMap.getDataMap().putLong(DataMapKeys.TIMESTAMP, timestamp); dataMap.getDataMap().putFloatArray(DataMapKeys.VALUES, values); PutDataRequest putDataRequest = dataMap.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } }); }
Example #10
Source File: FixturesFragment.java From aws-device-farm-sample-app-for-android with Apache License 2.0 | 5 votes |
private synchronized void buildGoogleApiClient() { googleApiClient = new GoogleApiClient.Builder(getActivity()) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); }
Example #11
Source File: BraintreeFragmentTest.java From braintree_android with MIT License | 5 votes |
@Test(timeout = 6000) public void getGoogleApiClient_returnsGoogleApiClient() throws InterruptedException { BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, mClientToken); fragment.getGoogleApiClient(new BraintreeResponseListener<GoogleApiClient>() { @Override public void onResponse(GoogleApiClient googleApiClient) { assertNotNull(googleApiClient); mCountDownLatch.countDown(); } }); mCountDownLatch.await(); }
Example #12
Source File: WearService.java From LibreAlarm with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); setupTextToSpeech(); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mGoogleApiClient.connect(); }
Example #13
Source File: GoogleApiClientBridge.java From friendspell with Apache License 2.0 | 5 votes |
public void unsubscribe(String token, MessageListener listener, ResultCallback<Status> callback) { GoogleApiClient googleApiClient = clients.get(token); if (googleApiClient.isConnected()) { Nearby.Messages.unsubscribe(googleApiClient, listener) .setResultCallback(callback); } }
Example #14
Source File: MainActivity.java From ExamplesAndroid with Apache License 2.0 | 5 votes |
protected synchronized void buildGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); mGoogleApiClient.connect(); }
Example #15
Source File: Utils.java From wear-os-samples with Apache License 2.0 | 5 votes |
/** * Get a list of all wearable nodes that are connected synchronously. * Only call this method from a background thread (it should never be * called from the main/UI thread as it blocks). */ public static Collection<String> getNodes(GoogleApiClient client) { Collection<String> results= new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } return results; }
Example #16
Source File: LocationService.java From io.appium.settings with Apache License 2.0 | 5 votes |
private FusedLocationProvider createFusedLocationProvider() { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .build(); FusedLocationProviderClient locationProviderClient = LocationServices.getFusedLocationProviderClient(this); return new FusedLocationProvider(googleApiClient, locationProviderClient, this); }
Example #17
Source File: SnapshotCoordinator.java From Trivia-Knowledge with Apache License 2.0 | 5 votes |
@Override public PendingResult<OpenSnapshotResult> resolveConflict(GoogleApiClient googleApiClient, String conflictId, final Snapshot snapshot) { if (!isAlreadyOpen(snapshot.getMetadata().getUniqueName()) && !isAlreadyClosing(snapshot.getMetadata().getUniqueName())) { setIsOpening(snapshot.getMetadata().getUniqueName()); try { return new CoordinatedPendingResult<>( Games.Snapshots.resolveConflict(googleApiClient, conflictId, snapshot), new ResultListener() { @Override public void onResult(Result result) { if (!result.getStatus().isSuccess()) { setClosed(snapshot.getMetadata().getUniqueName()); } } }); } catch (RuntimeException e) { setClosed(snapshot.getMetadata().getUniqueName()); throw e; } } else { throw new IllegalStateException(snapshot.getMetadata().getUniqueName() + " is already open or is busy"); } }
Example #18
Source File: MyActivity.java From flopsydroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); mBtnOnWearable = (ImageView) findViewById(R.id.startWearable); mBtnOnWearable.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getNodes(new OnGotNodesListener() { @Override public void onGotNodes(ArrayList<String> nodes) { if(nodes.size() > 0) { Wearable.MessageApi.sendMessage( getGoogleApiClient(), nodes.get(0), "/flopsydroid/wear", null).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult result) { if (!result.getStatus().isSuccess()) { } } }); } } }); } }); mGoogleAppiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Wearable.API) .build(); }
Example #19
Source File: UtilityService.java From io2015-codelabs with Apache License 2.0 | 5 votes |
/** * Sends the actual message to ask other devices that are capable of showing "details" to start * the appropriate activity * * @param path the path to pass to the wearable message API * @param extraInfo extra info that varies based on the path being sent */ private void startDeviceActivityInternal(String path, String extraInfo) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (connectionResult.isSuccess() && googleApiClient.isConnected()) { CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability( googleApiClient, getApplicationContext().getString(R.string.show_detail_capability_name), CapabilityApi.FILTER_REACHABLE) .await(GET_CAPABILITY_TIMEOUT_S, TimeUnit.SECONDS); if (result.getStatus().isSuccess()) { Set<Node> nodes = result.getCapability().getNodes(); for (Node node : nodes) { Wearable.MessageApi.sendMessage( googleApiClient, node.getId(), path, extraInfo.getBytes()); } } else { Log.e(TAG, "startDeviceActivityInternal() Failed to get capabilities, status: " + result.getStatus().getStatusMessage()); } googleApiClient.disconnect(); } }
Example #20
Source File: GameHelper.java From Onesearch with MIT License | 5 votes |
/** * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally, * you do not have to do this; use this method only if you need to make * nonstandard setup (e.g. adding extra scopes for other APIs) on the * GoogleApiClient.Builder before calling @link{#setup}. */ public GoogleApiClient.Builder createApiClientBuilder() { if (mSetupDone) { String error = "GameHelper: you called GameHelper.createApiClientBuilder() after " + "calling setup. You can only get a client builder BEFORE performing setup."; logError(error); throw new IllegalStateException(error); } GoogleApiClient.Builder builder = new GoogleApiClient.Builder( mActivity, this, this); if (0 != (mRequestedClients & CLIENT_GAMES)) { builder.addApi(Games.API, mGamesApiOptions); builder.addScope(Games.SCOPE_GAMES); } if (0 != (mRequestedClients & CLIENT_PLUS)) { builder.addApi(Plus.API); builder.addScope(Plus.SCOPE_PLUS_LOGIN); } if (0 != (mRequestedClients & CLIENT_APPSTATE)) { builder.addApi(AppStateManager.API); builder.addScope(AppStateManager.SCOPE_APP_STATE); } if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) { builder.addScope(Drive.SCOPE_APPFOLDER); builder.addApi(Drive.API); } mGoogleApiClientBuilder = builder; return builder; }
Example #21
Source File: MainActivity.java From ETSMobile-Android2 with Apache License 2.0 | 5 votes |
private String getRemoteNodeId(GoogleApiClient googleApiClient) { NodeApi.GetConnectedNodesResult nodesResult = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); List<Node> nodes = nodesResult.getNodes(); if (nodes.size() > 0) { return nodes.get(0).getId(); } return null; }
Example #22
Source File: MainActivity.java From arcgis-runtime-demos-android with Apache License 2.0 | 5 votes |
private void initGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this) .addApi(Wearable.API) .addConnectionCallbacks(new WearConnectionCallbacks()) .addOnConnectionFailedListener(new WearConnectionFailedListener()) .build(); mGoogleApiClient.connect(); }
Example #23
Source File: ControllerFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
private synchronized void buildGoogleApiClient(@NonNull Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context.getApplicationContext()) // Use getApplicationContext to prevent memory leak: https://stackoverflow.com/questions/35308231/memory-leak-with-googleapiclient-detected-by-android-studio .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); }
Example #24
Source File: SecondActivity.java From journaldev with MIT License | 5 votes |
public void setUpGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addApi(Auth.CREDENTIALS_API) .enableAutoManage(this, this) .build(); }
Example #25
Source File: AuthActivity.java From andela-med-manager with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_auth); ButterKnife.bind(this); addUserViewModel = ViewModelProviders.of(this).get(AddUserViewModel.class); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); // Build a GoogleApiClient with access to the Google Sign-In Api and the // options specified by gso. mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivitgit y */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); loginButton.setOnClickListener(v -> { //Check Internet Connection // if (NetworkUtil.isConnected(this)) googleSignIn(); }); }
Example #26
Source File: LocationServicesApiBuilder.java From android_external_GmsLib with Apache License 2.0 | 5 votes |
@Override public ApiConnection build(Context context, Looper looper, Api.ApiOptions.NoOptions options, AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { return new LocationClientImpl(context, callbacks, connectionFailedListener); }
Example #27
Source File: DynamicLinksClient.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
public DynamicLinksClient( Context context, Looper looper, ClientSettings clientSettings, GoogleApiClient.ConnectionCallbacks connectedListener, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { super( context, looper, // ServiceId.DYNAMIC_LINKS_API_VALUE, 131, clientSettings, connectedListener, connectionFailedListener); }
Example #28
Source File: LogoutHelper.java From social-app-android with Apache License 2.0 | 5 votes |
private static void logoutByProvider(String providerId, GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) { switch (providerId) { case GoogleAuthProvider.PROVIDER_ID: logoutGoogle(mGoogleApiClient, fragmentActivity); break; case FacebookAuthProvider.PROVIDER_ID: logoutFacebook(fragmentActivity.getApplicationContext()); break; } }
Example #29
Source File: SetTimerActivity.java From AndroidWearable-Samples with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int paramLength = getIntent().getIntExtra(AlarmClock.EXTRA_LENGTH, 0); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "SetTimerActivity:onCreate=" + paramLength); } if (paramLength > 0 && paramLength <= 86400) { long durationMillis = paramLength * 1000; setupTimer(durationMillis); finish(); return; } Resources res = getResources(); for (int i = 0; i < NUMBER_OF_TIMES; i++) { mTimeOptions[i] = new ListViewItem( res.getQuantityString(R.plurals.timer_minutes, i + 1, i + 1), (i + 1) * 60 * 1000); } setContentView(R.layout.timer_set_timer); // Initialize a simple list of countdown time options. mListView = (ListView) findViewById(R.id.times_list_view); ArrayAdapter<ListViewItem> arrayAdapter = new ArrayAdapter<ListViewItem>(this, android.R.layout.simple_list_item_1, mTimeOptions); mListView.setAdapter(arrayAdapter); mListView.setOnItemClickListener(this); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); }
Example #30
Source File: RegistrationIntentService.java From friendlyping with Apache License 2.0 | 5 votes |
/** * Sends the registration to the server. * * @param token The token to send. * @throws IOException Thrown when a connection issue occurs. */ private void sendRegistrationToServer(String token) throws IOException { final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_PROFILE) .build(); googleApiClient.blockingConnect(); Bundle registration = createRegistrationBundle(googleApiClient); registration.putString(PingerKeys.REGISTRATION_TOKEN, token); // Register the user at the server. GoogleCloudMessaging.getInstance(this).send(FriendlyPingUtil.getServerUrl(this), String.valueOf(System.currentTimeMillis()), registration); }