com.google.android.gms.common.Scopes Java Examples
The following examples show how to use
com.google.android.gms.common.Scopes.
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: SignInActivityWithDrive.java From google-services with Apache License 2.0 | 10 votes |
@Override public void onStart() { super.onStart(); // Check if the user is already signed in and all required scopes are granted GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this); if (account != null && GoogleSignIn.hasPermissions(account, new Scope(Scopes.DRIVE_APPFOLDER))) { updateUI(account); } else { updateUI(null); } }
Example #2
Source File: GoogleLoginInstance.java From ShareLoginPayUtil with Apache License 2.0 | 6 votes |
public GoogleLoginInstance(Activity activity, LoginListener listener, boolean fetchUserInfo) { super(activity, listener, fetchUserInfo); mClientId = ShareManager.CONFIG.getGoogleClientId(); mClientSecret = ShareManager.CONFIG.getGoogleClientSecret(); mClient = new OkHttpClient.Builder().build(); GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(mClientId) .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER), new Scope(Scopes.OPEN_ID), new Scope(Scopes.PLUS_ME)) .requestServerAuthCode(mClientId) .requestProfile() .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(activity, signInOptions); }
Example #3
Source File: Utils.java From google-signin with MIT License | 6 votes |
static GoogleSignInOptions getSignInOptions( final Scope[] scopes, final String webClientId, final boolean offlineAccess, final boolean forceCodeForRefreshToken, final String accountName, final String hostedDomain ) { GoogleSignInOptions.Builder googleSignInOptionsBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.EMAIL), scopes); if (webClientId != null && !webClientId.isEmpty()) { googleSignInOptionsBuilder.requestIdToken(webClientId); if (offlineAccess) { googleSignInOptionsBuilder.requestServerAuthCode(webClientId, forceCodeForRefreshToken); } } if (accountName != null && !accountName.isEmpty()) { googleSignInOptionsBuilder.setAccountName(accountName); } if (hostedDomain != null && !hostedDomain.isEmpty()) { googleSignInOptionsBuilder.setHostedDomain(hostedDomain); } return googleSignInOptionsBuilder.build(); }
Example #4
Source File: DataManager.java From GoogleFitExample with Apache License 2.0 | 6 votes |
/** * Build a {@link GoogleApiClient} that will authenticate the user and allow the application * to connect to Fitness APIs. The scopes included should match the scopes your app needs * (see documentation for details). Authentication will occasionally fail intentionally, * and in those cases, there will be a known resolution, which the OnConnectionFailedListener() * can address. Examples of this include the user never having signed in before, or * having multiple accounts on the device and needing to specify which account to use, etc. */ private void buildFitnessClient(final Context context) { if (context != null) { Log.i(TAG, "Creating the Google API Client with context: " + context.getClass().getName()); // Create the Google API Client mClient = new GoogleApiClient.Builder(context) .addApiIfAvailable(Fitness.SENSORS_API) .addApi(Fitness.SESSIONS_API) .addApi(Fitness.HISTORY_API) .addApi(Fitness.RECORDING_API) //.addApi(LocationServices.API) .addScope(new Scope(Scopes.PROFILE)) //.addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE)) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } }
Example #5
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState != null) { authInProgress = savedInstanceState.getBoolean(AUTH_PENDING); } mApiClient = new GoogleApiClient.Builder(this) .addApi(Fitness.SENSORS_API) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); }
Example #6
Source File: GoogleFitManager.java From react-native-google-fit with MIT License | 5 votes |
public void disconnect(Context context) { GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(context, options); GoogleSignInAccount gsa = GoogleSignIn.getAccountForScopes(mReactContext, new Scope(Scopes.FITNESS_ACTIVITY_READ)); Fitness.getConfigClient(mReactContext, gsa).disableFit(); mApiClient.disconnect(); googleSignInClient.signOut(); }
Example #7
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 #8
Source File: GooglePlay.java From ExtensionsPack with MIT License | 5 votes |
public static void start(Context ctx) { gamesClient = new GamesClient.Builder(ctx, new GooglePlayCallback("GAMES_CLIENT"), new GooglePlayCallback("GAMES_CLIENT")) .setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL) .setScopes(Scopes.GAMES) .create(); appStateClient = new AppStateClient.Builder(ctx, new GooglePlayCallback("APP_STATE_CLIENT"), new GooglePlayCallback("APP_STATE_CLIENT")) .setScopes(Scopes.APP_STATE) .create(); }
Example #9
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initViews(); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Fitness.HISTORY_API) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) .addConnectionCallbacks(this) .enableAutoManage(this, 0, this) .build(); }
Example #10
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Fitness.SESSIONS_API) .addApi(Fitness.HISTORY_API) .addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE)) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) .addConnectionCallbacks(this) .enableAutoManage(this, 0, this) .build(); }
Example #11
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initViews(); initCallbacks(); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Fitness.RECORDING_API) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ)) .addConnectionCallbacks(this) .enableAutoManage(this, 0, this) .build(); }
Example #12
Source File: MainActivity.java From android-google-accounts with Apache License 2.0 | 5 votes |
/** * Construct a client. * * @return un-connected client. */ protected synchronized void rebuildGoogleApiClient() { // When we build the GoogleApiClient we specify where connected and connection failed // callbacks should be returned, which Google APIs our app uses and which OAuth 2.0 // scopes our app requests. mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) // TODO(developer): Specify any additional API Scopes or APIs you need here. // The GoogleApiClient will ensure these APIs are available, and the Scopes // are approved before invoking the onConnected callbacks. .build(); }
Example #13
Source File: MainActivity.java From android-google-accounts with Apache License 2.0 | 5 votes |
/** * Construct a client using AutoManage functionality. */ protected synchronized void rebuildGoogleApiClient() { // When we build the GoogleApiClient we specify where connected and connection failed // callbacks should be returned, which Google APIs our app uses and which OAuth 2.0 // scopes our app requests. When using enableAutoManage to register the failed connection // listener it will only be called back when auto-resolution attempts were not // successful or possible. A normal ConnectionFailedListener is also registered below to // notify the activity when it needs to stop making API calls. mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, 0 /* googleApiClientId used when auto-managing multiple googleApiClients */, this /* OnConnectionFailedListener */) .addConnectionCallbacks(this /* ConnectionCallbacks */) // Register a connection listener that will notify on disconnect (including ones // caused by calling disconnect on the GoogleApiClient). .addOnConnectionFailedListener(new OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult connectionResult) { googleApiClientConnectionStateChange(true); } }) .addApi(Plus.API) .addScope(new Scope(Scopes.PLUS_ME)) // TODO(developer): Specify any additional API Scopes or APIs you need here. // The GoogleApiClient will ensure these APIs are available, and the Scopes // are approved before invoking the onConnected callbacks. .build(); }
Example #14
Source File: LoginWithGooglePlusSDKActivity.java From Android-SDK with MIT License | 5 votes |
private void configureGooglePlusSDK() { GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PROFILE), new Scope(Scopes.PLUS_ME)) .requestId() .requestIdToken(getString(R.string.gp_WebApp_ClientId)) .requestServerAuthCode(getString(R.string.gp_WebApp_ClientId), false) .requestEmail() .build(); mGoogleApiClient = new GoogleApiClient.Builder(this) //.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) //.addOnConnectionFailedListener(this) .addApi(Auth.CREDENTIALS_API) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) // .addScope(new Scope(Scopes.PROFILE)) // .addScope(new Scope(Scopes.PLUS_ME)) .build(); loginGooglePlusButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(signInIntent, RC_SIGN_IN); } }); }
Example #15
Source File: LoginActivity.java From platform-friends-android with BSD 2-Clause "Simplified" License | 5 votes |
private void onGoogleLogin() { this.mPlusClient = new PlusClient .Builder(this, this, this) .setScopes(Scopes.PLUS_LOGIN + " " + "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email") .build(); connectionProgressDialog.show(); this.mPlusClient.connect(); }
Example #16
Source File: AuthUiActivity.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
private List<String> getGoogleScopes() { List<String> result = new ArrayList<>(); if (mGoogleScopeYoutubeData.isChecked()) { result.add("https://www.googleapis.com/auth/youtube.readonly"); } if (mGoogleScopeDriveFile.isChecked()) { result.add(Scopes.DRIVE_FILE); } return result; }
Example #17
Source File: SignInActivityWithDrive.java From google-services with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Views mStatusTextView = findViewById(R.id.status); // Button listeners findViewById(R.id.sign_in_button).setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.disconnect_button).setOnClickListener(this); // [START configure_signin] // Configure sign-in to request the user's ID, email address, and basic // profile. ID and basic profile are included in DEFAULT_SIGN_IN. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) .requestEmail() .build(); // [END configure_signin] // [START build_client] // Build a GoogleSignInClient with access to the Google Sign-In API and the // options specified by gso. mGoogleSignInClient = GoogleSignIn.getClient(this, gso); // [END build_client] // [START customize_button] // Customize sign-in button. The sign-in button can be displayed in // multiple sizes. SignInButton signInButton = findViewById(R.id.sign_in_button); signInButton.setSize(SignInButton.SIZE_STANDARD); // [END customize_button] }
Example #18
Source File: ServerAuthCodeActivity.java From google-services with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Views mAuthCodeTextView = findViewById(R.id.detail); // Button click listeners findViewById(R.id.sign_in_button).setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.disconnect_button).setOnClickListener(this); // For sample only: make sure there is a valid server client ID. validateServerClientID(); // [START configure_signin] // Configure sign-in to request offline access to the user's ID, basic // profile, and Google Drive. The first time you request a code you will // be able to exchange it for an access token and refresh token, which // you should store. In subsequent calls, the code will only result in // an access token. By asking for profile access (through // DEFAULT_SIGN_IN) you will also get an ID Token as a result of the // code exchange. String serverClientId = getString(R.string.server_client_id); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) .requestServerAuthCode(serverClientId) .requestEmail() .build(); // [END configure_signin] mGoogleSignInClient = GoogleSignIn.getClient(this, gso); }
Example #19
Source File: AuthHelper.java From drip-steps with Apache License 2.0 | 5 votes |
public void buildFitnessClient(final Context context, final GoogleApiClient.ConnectionCallbacks connectionCallbacks, final GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { client = new GoogleApiClient.Builder(context.getApplicationContext()). addApi(Fitness.HISTORY_API). addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ)). addConnectionCallbacks(connectionCallbacks). addOnConnectionFailedListener(connectionFailedListener) .build(); }
Example #20
Source File: LoginPresenterImpl.java From Saude-no-Mapa with MIT License | 5 votes |
private void configureGoogleClient() { mGso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PLUS_LOGIN)) .requestEmail() .build(); mGoogleApiClient = new GoogleApiClient.Builder(mContext) .enableAutoManage((LoginActivity) mContext, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, mGso) .build(); mView.setGoogleButtonScope(mGso); }
Example #21
Source File: GoogleImpl.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
private GoogleApiClient getClient(SuccessCallback<GoogleApiClient> onConnected) { if (mGoogleApiClient == null) { Context ctx = AndroidNativeUtil.getContext(); if (mGoogleApiClient == null) { GoogleSignInOptions gso; if (clientId != null && clientSecret != null) { System.out.println("Generating GoogleSignIn for clientID="+clientId); List<Scope> includeScopes = new ArrayList<Scope>(); Scope firstScope = new Scope(Scopes.PROFILE); if (scope != null) { for (String str : Util.split(scope, " ")) { if ("profile".equals(str)) { //str = Scopes.PROFILE; continue; } else if ("email".equals(str)) { str = Scopes.EMAIL; } else if (Scopes.PROFILE.equals(str)) { continue; } if (str.trim().isEmpty()) { continue; } includeScopes.add(new Scope(str.trim())); } } gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) //.requestIdToken("555462747934-iujpd5saj4pjpibo7c6r9tbjfef22rh1.apps.googleusercontent.com") .requestIdToken(clientId) .requestScopes(firstScope, includeScopes.toArray(new Scope[includeScopes.size()])) //.requestScopes(Plus.SCOPE_PLUS_PROFILE) //.requestServerAuthCode("555462747934-iujpd5saj4pjpibo7c6r9tbjfef22rh1.apps.googleusercontent.com") .requestServerAuthCode(clientId) .build(); } else { System.out.println("Generating GoogleSignIn without ID token"); gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build(); } mGoogleApiClient = new GoogleApiClient.Builder(ctx) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); } } if (mGoogleApiClient.isConnected()) { if (onConnected != null) { onConnected.onSucess(mGoogleApiClient); } } else { synchronized(onConnectedCallbacks) { if (onConnected != null) { onConnectedCallbacks.add(onConnected); } if (!mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL); } } } return mGoogleApiClient; }
Example #22
Source File: SleepHistory.java From react-native-google-fit with MIT License | 4 votes |
@RequiresApi(api = Build.VERSION_CODES.N) public void getSleepData(double startDate, double endDate, final Callback errorCallback, final Callback successCallback) { SessionReadRequest request = new SessionReadRequest.Builder() .readSessionsFromAllApps() .read(DataType.TYPE_ACTIVITY_SEGMENT) .setTimeInterval((long) startDate, (long) endDate, TimeUnit.MILLISECONDS) .build(); GoogleSignInAccount gsa = GoogleSignIn.getAccountForScopes(this.mReactContext, new Scope(Scopes.FITNESS_ACTIVITY_READ)); Fitness.getSessionsClient(this.mReactContext, gsa) .readSession(request) .addOnSuccessListener(new OnSuccessListener<SessionReadResponse>() { @Override public void onSuccess(SessionReadResponse response) { List<Object> sleepSessions = response.getSessions() .stream() .filter(new Predicate<Session>() { @Override public boolean test(Session s) { Log.i(TAG, "Activity found: " + s.getActivity()); return s.getActivity().equals(FitnessActivities.SLEEP); } }) .collect(Collectors.toList()); WritableArray sleep = Arguments.createArray(); for (Object session : sleepSessions) { List<DataSet> dataSets = response.getDataSet((Session) session); for (DataSet dataSet : dataSets) { processDataSet(dataSet, (Session) session, sleep); } } successCallback.invoke(sleep); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.i(TAG, "Failure: " + e.getMessage()); errorCallback.invoke(e.getMessage()); } }); }