Java Code Examples for com.google.android.gms.drive.Drive#getDriveResourceClient()

The following examples show how to use com.google.android.gms.drive.Drive#getDriveResourceClient() . 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: RemoteBackup.java    From Database-Backup-Restore with Apache License 2.0 5 votes vote down vote up
public void connectToDrive(boolean backup) {
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(activity);
    if (account == null) {
        signIn();
    } else {
        //Initialize the drive api
        mDriveClient = Drive.getDriveClient(activity, account);
        // Build a drive resource client.
        mDriveResourceClient = Drive.getDriveResourceClient(activity, account);
        if (backup)
            startDriveBackup();
        else
            startDriveRestore();
    }
}
 
Example 2
Source File: DriveSyncService.java    From Passbook with Apache License 2.0 5 votes vote down vote up
@Override
public SyncService connect(Activity context, int localVersion) {
    mLocalVersion = localVersion;
    if (mSignInAccount == null) {
        Intent intent = mGoogleSignClient.getSignInIntent();
        context.startActivityForResult(intent, CA.AUTH);
    } else {
        mDriveResourceClient = Drive.getDriveResourceClient(context, mSignInAccount);
        mExecutorService.submit(this::read);
    }
    return this;
}
 
Example 3
Source File: DriveSyncService.java    From Passbook with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data){
    if (requestCode == CA.AUTH) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            mSignInAccount = task.getResult(ApiException.class);
            mDriveResourceClient = Drive.getDriveResourceClient(activity, mSignInAccount);
            mListener.onSyncProgress(CA.AUTH);
            read();
        } catch (ApiException e) {
            Log.e(LOG_TAG, "onActivityResult: ",  e);
            mListener.onSyncFailed(CA.CONNECTION);
        }
    }
}
 
Example 4
Source File: MainActivity.java    From drive-android-quickstart with Apache License 2.0 4 votes vote down vote up
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  switch (requestCode) {
    case REQUEST_CODE_SIGN_IN:
      Log.i(TAG, "Sign in request code");
      // Called after user is signed in.
      if (resultCode == RESULT_OK) {
        Log.i(TAG, "Signed in successfully.");
        // Use the last signed in account here since it already have a Drive scope.
        mDriveClient = Drive.getDriveClient(this, GoogleSignIn.getLastSignedInAccount(this));
        // Build a drive resource client.
        mDriveResourceClient =
            Drive.getDriveResourceClient(this, GoogleSignIn.getLastSignedInAccount(this));
        // Start camera.
        startActivityForResult(
            new Intent(MediaStore.ACTION_IMAGE_CAPTURE), REQUEST_CODE_CAPTURE_IMAGE);
      }
      break;
    case REQUEST_CODE_CAPTURE_IMAGE:
      Log.i(TAG, "capture image request code");
      // Called after a photo has been taken.
      if (resultCode == Activity.RESULT_OK) {
        Log.i(TAG, "Image captured successfully.");
        // Store the image data as a bitmap for writing later.
        mBitmapToSave = (Bitmap) data.getExtras().get("data");
        saveFileToDrive();
      }
      break;
    case REQUEST_CODE_CREATOR:
      Log.i(TAG, "creator request code");
      // Called after a file is saved to Drive.
      if (resultCode == RESULT_OK) {
        Log.i(TAG, "Image successfully saved.");
        mBitmapToSave = null;
        // Just start the camera again for another photo.
        startActivityForResult(
            new Intent(MediaStore.ACTION_IMAGE_CAPTURE), REQUEST_CODE_CAPTURE_IMAGE);
      }
      break;
  }
}
 
Example 5
Source File: BaseDemoActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Continues the sign-in process, initializing the Drive clients with the current
 * user's account.
 */
private void initializeDriveClient(GoogleSignInAccount signInAccount) {
    mDriveClient = Drive.getDriveClient(getApplicationContext(), signInAccount);
    mDriveResourceClient = Drive.getDriveResourceClient(getApplicationContext(), signInAccount);
    onDriveClientReady();
}
 
Example 6
Source File: MainActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  switch (requestCode) {
    case REQUEST_CODE_SIGN_IN:
      Log.i(TAG, "Sign in request code");
      // Called after user is signed in.
      if (resultCode == RESULT_OK) {
        Log.i(TAG, "Signed in successfully.");
        // Use the last signed in account here since it already have a Drive scope.
        mDriveClient = Drive.getDriveClient(this, GoogleSignIn.getLastSignedInAccount(this));
        // Build a drive resource client.
        mDriveResourceClient =
            Drive.getDriveResourceClient(this, GoogleSignIn.getLastSignedInAccount(this));
        // Start camera.
        startActivityForResult(
            new Intent(MediaStore.ACTION_IMAGE_CAPTURE), REQUEST_CODE_CAPTURE_IMAGE);
      }
      break;
    case REQUEST_CODE_CAPTURE_IMAGE:
      Log.i(TAG, "capture image request code");
      // Called after a photo has been taken.
      if (resultCode == Activity.RESULT_OK) {
        Log.i(TAG, "Image captured successfully.");
        // Store the image data as a bitmap for writing later.
        mBitmapToSave = (Bitmap) data.getExtras().get("data");
        saveFileToDrive();
      }
      break;
    case REQUEST_CODE_CREATOR:
      Log.i(TAG, "creator request code");
      // Called after a file is saved to Drive.
      if (resultCode == RESULT_OK) {
        Log.i(TAG, "Image successfully saved.");
        mBitmapToSave = null;
        // Just start the camera again for another photo.
        startActivityForResult(
            new Intent(MediaStore.ACTION_IMAGE_CAPTURE), REQUEST_CODE_CAPTURE_IMAGE);
      }
      break;
  }
}
 
Example 7
Source File: BaseDemoActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Continues the sign-in process, initializing the DriveResourceClient with the current
 * user's account.
 */
private void initializeDriveClient(GoogleSignInAccount signInAccount) {
    mDriveClient = Drive.getDriveClient(getApplicationContext(), signInAccount);
    mDriveResourceClient = Drive.getDriveResourceClient(getApplicationContext(), signInAccount);
    onDriveClientReady();
}
 
Example 8
Source File: MainActivity.java    From android-samples with Apache License 2.0 2 votes vote down vote up
/**
 * Continues the sign-in process, initializing the DriveResourceClient with the current
 * user's account.
 *
 * @param signInAccount Authorized google account
 */
private void initializeDriveResourceClient(GoogleSignInAccount signInAccount) {
    mDriveResourceClient = Drive.getDriveResourceClient(getApplicationContext(), signInAccount);
    onDriveClientReady();
}