Example usage for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential setSelectedAccount

List of usage examples for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential setSelectedAccount

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential setSelectedAccount.

Prototype

public final GoogleAccountCredential setSelectedAccount(Account selectedAccount) 

Source Link

Document

Sets the selected Google Account or null for none.

Usage

From source file:com.weebly.opus1269.clipman.backup.DriveServiceHelper.java

License:Open Source License

/** get the DriveService */
@NonNull//from w ww  . j  a v a  2 s.c om
private Drive getDriveService() throws DriveException {
    checkAppFolderPermission();
    Drive service = null;
    final HttpTransport httpTransport = new NetHttpTransport();
    final JacksonFactory jsonFactory = new JacksonFactory();
    final String email = User.INST(mAppCtxt).getEmail();
    final Collection<String> scopes = new ArrayList<>(Collections.singletonList(DriveScopes.DRIVE_APPDATA));

    if (!TextUtils.isEmpty(email)) {
        // Use the authenticated account to sign in to the Drive service.
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(mAppCtxt, scopes);
        credential.setSelectedAccount(new Account(email, "com.google"));
        service = new Drive.Builder(httpTransport, jsonFactory, credential)
                .setApplicationName(mAppCtxt.getString(R.string.app_name)).build();
    }
    if (service == null) {
        throw new DriveException(ERR_INTERNAL);
    }

    return service;
}