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

The following examples show how to use com.google.android.gms.drive.Drive#getDriveClient() . 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: 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 3
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 4
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 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 DriveResourceClient with the current
 * user's account.
 */
private void initializeDriveClient(GoogleSignInAccount signInAccount) {
    mDriveClient = Drive.getDriveClient(getApplicationContext(), signInAccount);
    mDriveResourceClient = Drive.getDriveResourceClient(getApplicationContext(), signInAccount);
    onDriveClientReady();
}