Java Code Examples for com.google.android.gms.common.api.GoogleApiClient#Builder
The following examples show how to use
com.google.android.gms.common.api.GoogleApiClient#Builder .
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: GpgsClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
/** * Initializes the GoogleApiClient. Give your main AndroidLauncher as context. * <p> * Don't forget to add onActivityResult method there with call to onGpgsActivityResult. * * @param context your AndroidLauncher class * @param enableDriveAPI true if you activate save gamestate feature * @return this for method chunking */ public GpgsClient initialize(Activity context, boolean enableDriveAPI) { if (mGoogleApiClient != null) throw new IllegalStateException("Already initialized."); myContext = context; // retry some times when connect fails (needed when game state sync is enabled) firstConnectAttempt = MAX_CONNECTFAIL_RETRIES; GoogleApiClient.Builder builder = new GoogleApiClient.Builder(myContext) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Games.API).addScope(Games.SCOPE_GAMES); driveApiEnabled = enableDriveAPI; if (driveApiEnabled) builder.addScope(Drive.SCOPE_APPFOLDER); // add other APIs and scopes here as needed mGoogleApiClient = builder.build(); return this; }
Example 2
Source File: GooglePlusNetwork.java From EasyLogin with MIT License | 6 votes |
public GooglePlusNetwork(Activity activity) { sharedPrefs = activity.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE); this.activity = new WeakReference<>(activity); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); GoogleApiClient.Builder googleApiBuilder = new GoogleApiClient.Builder(activity); if (activity instanceof FragmentActivity) { googleApiBuilder.enableAutoManage((FragmentActivity) activity, this); } else { googleApiBuilder .addConnectionCallbacks(this) .addOnConnectionFailedListener(this); } googleApiClient = googleApiBuilder .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); }
Example 3
Source File: SoomlaGooglePlus.java From android-profile with Apache License 2.0 | 6 votes |
private void login(boolean enableGameServices) { GoogleApiClient.Builder clientBuilder = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API, Plus.PlusOptions.builder().build()) .addScope(Plus.SCOPE_PLUS_LOGIN); if (enableGameServices) { clientBuilder .addApi(Games.API, Games.GamesOptions.builder().build()) .addScope(Games.SCOPE_GAMES); } googleApiClient = clientBuilder.build(); if (!googleApiClient.isConnecting()){ signInRequested = true; googleApiClient.connect(); } }
Example 4
Source File: GameHelper.java From dice-heroes with GNU General Public License v3.0 | 6 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_SNAPSHOT)) { builder.addScope(Drive.SCOPE_APPFOLDER); builder.addApi(Drive.API); } mGoogleApiClientBuilder = builder; return builder; }
Example 5
Source File: GameHelper.java From FlappyCow 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_SNAPSHOT)) { builder.addScope(Drive.SCOPE_APPFOLDER); builder.addApi(Drive.API); } mGoogleApiClientBuilder = builder; return builder; }
Example 6
Source File: AppLocationCompatActivity.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) { if (mGoogleApiClient != null) mGoogleApiClient.disconnect(); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this). addConnectionCallbacks(this).addOnConnectionFailedListener(this); if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) { addApi(value); } mGoogleApiClient = builder.build(); if (!servicesConnected()) mGoogleApiClient.connect(); }
Example 7
Source File: AppLocationSupportFragment.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) { if (mGoogleApiClient != null) mGoogleApiClient.disconnect(); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API).enableAutoManage((FragmentActivity) mContext, new Random().nextInt(Integer.MAX_VALUE), this). addConnectionCallbacks(this).addOnConnectionFailedListener(this); for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) { if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) { builder.addApi(options); } } mGoogleApiClient = builder.build(); if (!servicesConnected()) mGoogleApiClient.connect(); }
Example 8
Source File: Activity_Main.java From Pedometer with Apache License 2.0 | 5 votes |
@Override protected void onCreate(final Bundle b) { super.onCreate(b); if (Build.VERSION.SDK_INT >= 26) { API26Wrapper.startForegroundService(this, new Intent(this, SensorListener.class)); } else { startService(new Intent(this, SensorListener.class)); } if (b == null) { // Create new fragment and transaction Fragment newFragment = new Fragment_Overview(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this // fragment, // and add the transaction to the back stack transaction.replace(android.R.id.content, newFragment); // Commit the transaction transaction.commit(); } GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this, this, this); builder.addApi(Games.API, Games.GamesOptions.builder().build()); builder.addScope(Games.SCOPE_GAMES); builder.addApi(Fitness.HISTORY_API); builder.addApi(Fitness.RECORDING_API); builder.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)); mGoogleApiClient = builder.build(); if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PermissionChecker.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); } }
Example 9
Source File: AppLocationActivity.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) { if (mGoogleApiClient != null) mGoogleApiClient.disconnect(); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this). addConnectionCallbacks(this).addOnConnectionFailedListener(this); for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) { if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) { builder.addApi(options); } } mGoogleApiClient = builder.build(); if (!servicesConnected()) mGoogleApiClient.connect(); }
Example 10
Source File: AppLocationCompatActivity.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) { if (mGoogleApiClient != null) mGoogleApiClient.disconnect(); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this). addConnectionCallbacks(this).addOnConnectionFailedListener(this); for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) { if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) { builder.addApi(options); } } mGoogleApiClient = builder.build(); if (!servicesConnected()) mGoogleApiClient.connect(); }
Example 11
Source File: AppLocationFragment.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) { if (mGoogleApiClient != null) mGoogleApiClient.disconnect(); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API).enableAutoManage((FragmentActivity) mContext, new Random().nextInt(Integer.MAX_VALUE), this). addConnectionCallbacks(this).addOnConnectionFailedListener(this); for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) { if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) { builder.addApi(options); } } mGoogleApiClient = builder.build(); if (!servicesConnected()) mGoogleApiClient.connect(); }
Example 12
Source File: AppLocationFragment.java From GooglePlayServiceLocationSupport with Apache License 2.0 | 5 votes |
@Override public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) { if (mGoogleApiClient != null) mGoogleApiClient.disconnect(); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API).enableAutoManage((FragmentActivity) mContext, new Random().nextInt(Integer.MAX_VALUE), this). addConnectionCallbacks(this).addOnConnectionFailedListener(this); if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) { addApi(value); } mGoogleApiClient = builder.build(); if (!servicesConnected()) mGoogleApiClient.connect(); }
Example 13
Source File: GacFragment.java From easygoogle with Apache License 2.0 | 5 votes |
private void buildGoogleApiClient() { Log.d(TAG, "buildGoogleApiClient: " + mModules); // Can't build a GoogleApiClient with no APIs if (mModules.size() == 0) { Log.w(TAG, "No APIs, not building GoogleApiClient."); return; } GoogleApiClient.Builder builder = new GoogleApiClient.Builder(getActivity()) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this); for (GacModule<?> api : mModules.values()) { for (Api apiObj : api.getApis()) { // Add Api with options, if possible Api.ApiOptions.HasOptions options = api.getOptionsFor(apiObj); if (options != null) { builder.addApi(apiObj, options); } else { builder.addApi(apiObj); } } for (Scope scopeObj : api.getScopes()) { builder.addScope(scopeObj); } } mGoogleApiClient = builder.build(); }
Example 14
Source File: GameHelper.java From ColorPhun with Apache License 2.0 | 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 15
Source File: GameHelper.java From ANE-Google-Play-Game-Services with Apache License 2.0 | 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); } mGoogleApiClientBuilder = builder; return builder; }
Example 16
Source File: GameHelper.java From Trivia-Knowledge with Apache License 2.0 | 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_SNAPSHOT)) { builder.addScope(Drive.SCOPE_APPFOLDER); builder.addApi(Drive.API); } mGoogleApiClientBuilder = builder; return builder; }
Example 17
Source File: GameHelper.java From tedroid with Apache License 2.0 | 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); } mGoogleApiClientBuilder = builder; return builder; }
Example 18
Source File: ApiClientAsyncTask.java From faceswap with Apache License 2.0 | 4 votes |
public ApiClientAsyncTask(Context context) { GoogleApiClient.Builder builder = new GoogleApiClient.Builder(context) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE); mClient = builder.build(); }
Example 19
Source File: RxLocationBaseOnSubscribe.java From RxGps with Apache License 2.0 | 4 votes |
protected GoogleApiClient.Builder getApiClientBuilder() { return new GoogleApiClient.Builder(ctx); }
Example 20
Source File: GApiClientAsyncTask.java From ToDay with MIT License | 4 votes |
public GApiClientAsyncTask(Context context) { GoogleApiClient.Builder builder = new GoogleApiClient.Builder(context) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE); mClient = builder.build(); }