com.google.android.gms.common.api.Scope Java Examples

The following examples show how to use com.google.android.gms.common.api.Scope. 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 vote down vote up
@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: RestApiActivity.java    From google-services with Apache License 2.0 9 votes vote down vote up
@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 (GoogleSignIn.hasPermissions(account, new Scope(CONTACTS_SCOPE))) {
        updateUI(account);
    } else {
        updateUI(null);
    }
}
 
Example #3
Source File: BaseDemoActivity.java    From android-samples with Apache License 2.0 8 votes vote down vote up
/**
 * Starts the sign-in process and initializes the Drive client.
 */
protected void signIn() {
    Set<Scope> requiredScopes = new HashSet<>(2);
    requiredScopes.add(Drive.SCOPE_FILE);
    requiredScopes.add(Drive.SCOPE_APPFOLDER);
    GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(this);
    if (signInAccount != null && signInAccount.getGrantedScopes().containsAll(requiredScopes)) {
        initializeDriveClient(signInAccount);
    } else {
        GoogleSignInOptions signInOptions =
                new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                  .requestScopes(Drive.SCOPE_FILE)
                  .requestScopes(Drive.SCOPE_APPFOLDER)
                  .build();
        GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(this, signInOptions);
        startActivityForResult(googleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN);
    }
}
 
Example #4
Source File: GoogleLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
@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: LoginFragment.java    From androidpay-quickstart with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    if (args != null) {
        mLoginAction = args.getInt(LoginActivity.EXTRA_ACTION);
    }

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestScopes(new Scope(WALLET_SCOPE))
            .build();

    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
            .enableAutoManage(getActivity(), this)
            .addConnectionCallbacks(this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
}
 
Example #7
Source File: DataManager.java    From GoogleFitExample with Apache License 2.0 6 votes vote down vote up
/**
 *  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 #8
Source File: Utils.java    From google-signin with MIT License 6 votes vote down vote up
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 #9
Source File: Utils.java    From google-signin with MIT License 6 votes vote down vote up
static WritableMap getUserProperties(@NonNull GoogleSignInAccount acct) {
    Uri photoUrl = acct.getPhotoUrl();

    WritableMap user = Arguments.createMap();
    user.putString("id", acct.getId());
    user.putString("name", acct.getDisplayName());
    user.putString("givenName", acct.getGivenName());
    user.putString("familyName", acct.getFamilyName());
    user.putString("email", acct.getEmail());
    user.putString("photo", photoUrl != null ? photoUrl.toString() : null);

    WritableMap params = Arguments.createMap();
    params.putMap("user", user);
    params.putString("idToken", acct.getIdToken());
    params.putString("serverAuthCode", acct.getServerAuthCode());

    WritableArray scopes = Arguments.createArray();
    for (Scope scope : acct.getGrantedScopes()) {
        String scopeString = scope.toString();
        if (scopeString.startsWith("http")) {
            scopes.pushString(scopeString);
        }
    }
    params.putArray("scopes", scopes);
    return params;
}
 
Example #10
Source File: MainActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Starts a sign-in activity using {@link #REQUEST_CODE_SIGN_IN}.
 */
private void requestSignIn() {
    Log.d(TAG, "Requesting sign-in");

    GoogleSignInOptions signInOptions =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .requestScopes(new Scope(DriveScopes.DRIVE_FILE))
                    .build();
    GoogleSignInClient client = GoogleSignIn.getClient(this, signInOptions);

    // The result of the sign-in Intent is handled in onActivityResult.
    startActivityForResult(client.getSignInIntent(), REQUEST_CODE_SIGN_IN);
}
 
Example #11
Source File: MainActivity.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
private GoogleApiClient buildGoogleApiClient() {
    return new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API, Plus.PlusOptions.builder().build())
            .addScope(new Scope("email"))
            .build();
}
 
Example #12
Source File: AuthUI.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Set the scopes that your app will request when using Google sign-in. See all <a
 * href="https://developers.google.com/identity/protocols/googlescopes">available
 * scopes</a>.
 *
 * @param scopes additional scopes to be requested
 */
@NonNull
public GoogleBuilder setScopes(@NonNull List<String> scopes) {
    GoogleSignInOptions.Builder builder =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail();
    for (String scope : scopes) {
        builder.requestScopes(new Scope(scope));
    }
    return setSignInOptions(builder.build());
}
 
Example #13
Source File: LoginWithGooglePlusSDKActivity.java    From Android-SDK with MIT License 5 votes vote down vote up
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 #14
Source File: AuthManagerServiceImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private List<Scope> getScopes(String scope) {
    if (!scope.startsWith("oauth2:")) return null;
    String[] strings = scope.substring(7).split(" ");
    List<Scope> res = new ArrayList<Scope>();
    for (String string : strings) {
        res.add(new Scope(string));
    }
    return res;
}
 
Example #15
Source File: AbstractGmsServiceBroker.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private Scope[] scopesFromStringArray(String[] arr) {
    Scope[] scopes = new Scope[arr.length];
    for (int i = 0; i < arr.length; i++) {
        scopes[i] = new Scope(arr[i]);
    }
    return scopes;
}
 
Example #16
Source File: MainActivity.java    From android-google-accounts with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #17
Source File: MainActivity.java    From android-google-accounts with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #18
Source File: GoogleSignUpActivity.java    From socialmediasignup with MIT License 5 votes vote down vote up
private void setupScopes(GoogleSignInOptions.Builder builder) {
    List<Scope> scopes = getScopes();
    if (scopes.size() == 1) {
        builder.requestScopes(scopes.get(0));
    } else if (scopes.size() > 1) {
        List<Scope> restScopes = scopes.subList(1, scopes.size());
        Scope[] restScopesArray = new Scope[restScopes.size()];
        restScopesArray = scopes.toArray(restScopesArray);
        builder.requestScopes(scopes.get(0), restScopesArray);
    }
}
 
Example #19
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: GacFragment.java    From easygoogle with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: AndroidGoogleAccount.java    From QtAndroidTools with MIT License 5 votes vote down vote up
private GoogleSignInClient getSignInClient(String ScopeName)
{
    GoogleSignInOptions.Builder SignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);
    if(ScopeName.isEmpty() == false) SignInOptions.requestScopes(new Scope(ScopeName));
    SignInOptions.requestEmail();

    return GoogleSignIn.getClient(mActivityInstance, SignInOptions.build());
}
 
Example #23
Source File: Utils.java    From google-signin with MIT License 5 votes vote down vote up
@NonNull
static Scope[] createScopesArray(ReadableArray scopes) {
    int size = scopes.size();
    Scope[] _scopes = new Scope[size];

    for (int i = 0; i < size; i++) {
        String scopeName = scopes.getString(i);
        _scopes[i] = new Scope(scopeName);
    }
    return _scopes;
}
 
Example #24
Source File: GoogleFitManager.java    From react-native-google-fit with MIT License 5 votes vote down vote up
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 #25
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: RxLocationBaseOnSubscribe.java    From RxGps with Apache License 2.0 5 votes vote down vote up
protected RxLocationBaseOnSubscribe(@NonNull Context ctx, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] services, Scope[] scopes) {
    this.ctx = ctx;
    this.services = services;
    this.scopes = scopes;
    timeoutTime = null;
    timeoutUnit = null;
}
 
Example #27
Source File: RestApiActivity.java    From google-services with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Views
    mStatusTextView = findViewById(R.id.status);
    mDetailTextView = findViewById(R.id.detail);

    // Button listeners
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);

    // For this example we don't need the disconnect button
    findViewById(R.id.disconnect_button).setVisibility(View.GONE);

    // Restore instance state
    if (savedInstanceState != null) {
        mAccount = savedInstanceState.getParcelable(KEY_ACCOUNT);
    }

    // Configure sign-in to request the user's ID, email address, basic profile,
    // and readonly access to contacts.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope(CONTACTS_SCOPE))
            .requestEmail()
            .build();

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

    // Show a standard Google Sign In button. If your application does not rely on Google Sign
    // In for authentication you could replace this with a "Get Google Contacts" button
    // or similar.
    SignInButton signInButton = findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
}
 
Example #28
Source File: Activity_Main.java    From Pedometer with Apache License 2.0 5 votes vote down vote up
@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 #29
Source File: SignInActivityWithDrive.java    From google-services with Apache License 2.0 5 votes vote down vote up
@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 #30
Source File: ServerAuthCodeActivity.java    From google-services with Apache License 2.0 5 votes vote down vote up
@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);
}