com.google.android.gms.drive.Drive Java Examples

The following examples show how to use com.google.android.gms.drive.Drive. 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: GameSyncService.java    From Passbook with Apache License 2.0 9 votes vote down vote up
@Override
public SyncService initialize(Activity context) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
            .requestScopes(Drive.SCOPE_APPFOLDER)
            //.requestScopes(Games.SCOPE_GAMES)
            .build();
    mGoogleSignClient = GoogleSignIn.getClient(context, gso);
    mSignInAccount = GoogleSignIn.getLastSignedInAccount(context);
    return this;
}
 
Example #2
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 #3
Source File: GameHelper.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
      builder.addScope(Drive.SCOPE_APPFOLDER);
      builder.addApi(Drive.API);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #4
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

  log("onCreate.");
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // Create the client used to sign in.
  mGoogleSignInClient = GoogleSignIn.getClient(this,
      new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
          // Since we are using SavedGames, we need to add the SCOPE_APPFOLDER to access Google Drive.
          .requestScopes(Drive.SCOPE_APPFOLDER)
          .build());

  for (int id : LEVEL_BUTTON_IDS) {
    findViewById(id).setOnClickListener(this);
  }
  findViewById(R.id.button_next_world).setOnClickListener(this);
  findViewById(R.id.button_prev_world).setOnClickListener(this);
  findViewById(R.id.button_sign_in).setOnClickListener(this);
  findViewById(R.id.button_sign_out).setOnClickListener(this);
  ((RatingBar) findViewById(R.id.gameplay_rating)).setOnRatingBarChangeListener(this);
  mSaveGame = new SaveGame();
  updateUi();
  checkPlaceholderIds();
}
 
Example #5
Source File: GoogleDriveClient.java    From financisto with GNU General Public License v2.0 6 votes vote down vote up
private Status createFile(DriveFolder folder, String fileName, byte[] bytes) throws IOException {
    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle(fileName)
            .setMimeType(Export.BACKUP_MIME_TYPE).build();
    // Create a file in the root folder
    DriveApi.DriveContentsResult contentsResult = Drive.DriveApi.newDriveContents(googleApiClient).await();
    Status contentsResultStatus = contentsResult.getStatus();
    if (contentsResultStatus.isSuccess()) {
        DriveContents contents = contentsResult.getDriveContents();
        contents.getOutputStream().write(bytes);
        DriveFolder.DriveFileResult fileResult = folder.createFile(googleApiClient, changeSet, contents).await();
        return fileResult.getStatus();
    } else {
        return contentsResultStatus;
    }
}
 
Example #6
Source File: GoogleDriveClient.java    From financisto with GNU General Public License v2.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void doRestore(DoDriveRestore event) {
    try {
        ConnectionResult connectionResult = connect();
        if (connectionResult.isSuccess()) {
            DriveFile file = Drive.DriveApi.getFile(googleApiClient, event.selectedDriveFile.driveId);
            DriveApi.DriveContentsResult contentsResult = file.open(googleApiClient, DriveFile.MODE_READ_ONLY, null).await();
            if (contentsResult.getStatus().isSuccess()) {
                DriveContents contents = contentsResult.getDriveContents();
                try {
                    DatabaseImport.createFromGoogleDriveBackup(context, db, contents).importDatabase();
                    bus.post(new DriveRestoreSuccess());
                } finally {
                    contents.discard(googleApiClient);
                }
            } else {
                handleFailure(contentsResult.getStatus());
            }
        } else {
            handleConnectionResult(connectionResult);
        }
    } catch (Exception e) {
        handleError(e);
    }
}
 
Example #7
Source File: GoogleDriveClient.java    From financisto with GNU General Public License v2.0 6 votes vote down vote up
private ConnectionResult connect() throws ImportExportException {
    if (googleApiClient == null) {
        String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
        if (googleDriveAccount == null) {
            throw new ImportExportException(R.string.google_drive_account_required);
        }
        googleApiClient = new GoogleApiClient.Builder(context)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .setAccountName(googleDriveAccount)
                //.addConnectionCallbacks(this)
                //.addOnConnectionFailedListener(this)
                .build();
    }
    return googleApiClient.blockingConnect(1, TimeUnit.MINUTES);
}
 
Example #8
Source File: GpgsClient.java    From gdx-gamesvcs with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the GoogleApiClient. Give your main AndroidLauncher as context.
 * <p>
 * Don't forget to add onActivityResult method there with call to onGpgsActivityResult.
 *
 * @param context        your AndroidLauncher class
 * @param enableDriveAPI true if you activate save gamestate feature
 * @return this for method chunking
 */
public GpgsClient initialize(Activity context, boolean enableDriveAPI) {

    if (mGoogleApiClient != null)
        throw new IllegalStateException("Already initialized.");

    myContext = context;
    // retry some times when connect fails (needed when game state sync is enabled)
    firstConnectAttempt = MAX_CONNECTFAIL_RETRIES;

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(myContext)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES);

    driveApiEnabled = enableDriveAPI;
    if (driveApiEnabled)
        builder.addScope(Drive.SCOPE_APPFOLDER);

    // add other APIs and scopes here as needed

    mGoogleApiClient = builder.build();

    return this;
}
 
Example #9
Source File: PlayGameServices.java    From PGSGP with MIT License 6 votes vote down vote up
private void initializePlayGameServices(boolean enableSaveGamesFunctionality) {
    GoogleSignInOptions signInOptions = null;
     
    if (enableSaveGamesFunctionality) {
        GoogleSignInOptions.Builder signInOptionsBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
        signInOptionsBuilder.requestScopes(Drive.SCOPE_APPFOLDER).requestId();
        signInOptions = signInOptionsBuilder.build();
    } else {
        signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN;
    }
     
    godotCallbacksUtils = new GodotCallbacksUtils();
    connectionController = new ConnectionController(appActivity, signInOptions, godotCallbacksUtils);
    signInController = new SignInController(appActivity, godotCallbacksUtils, connectionController);
    achievementsController = new AchievementsController(appActivity, connectionController, godotCallbacksUtils);
    leaderboardsController = new LeaderboardsController(appActivity, godotCallbacksUtils, connectionController);
    eventsController = new EventsController(appActivity, connectionController, godotCallbacksUtils);
    playerStatsController = new PlayerStatsController(appActivity, connectionController, godotCallbacksUtils);
    savedGamesController = new SavedGamesController(appActivity, godotCallbacksUtils, connectionController);

    googleSignInClient = GoogleSignIn.getClient(appActivity, signInOptions);
}
 
Example #10
Source File: FileManager.java    From amiibo with GNU General Public License v2.0 6 votes vote down vote up
@DebugLog
private void readFileFromDrive(final MetadataBuffer meta_data, final DriveId drive_id) {
    Drive.DriveApi.getFile(_parent.getClient(), drive_id)
            .open(_parent.getClient(), DriveFile.MODE_READ_ONLY, null)
            .setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
                @Override
                public void onResult(DriveApi.DriveContentsResult driveContentsResult) {
                    try {
                        InputStream input = driveContentsResult.getDriveContents()
                                .getInputStream();
                        String total = consumeStream(input);

                        AmiiboFile amiibo_file = AmiiboFile.fromString(total.toString());
                        _parent.onFileRead(amiibo_file);
                        if (!meta_data.isClosed()) meta_data.release();
                    } catch (IOException e) {
                        e.printStackTrace();
                        _parent.onFileRead(null);
                    }
                }
            });
}
 
Example #11
Source File: CloudletDemoActivity.java    From faceswap with Apache License 2.0 6 votes vote down vote up
private void readFileFromGoogleDrive(){
    if (mGoogleApiClient !=null && mGoogleApiClient.isConnected()){
        // Let the user pick text file
        // no files selected by the user.
        //http://stackoverflow.com/questions/26331046/android-how-can-i-access-a-spreadsheet-with-the-google-drive-sdk
        // cannot open google doc file
        IntentSender intentSender = Drive.DriveApi
                .newOpenFileActivityBuilder()
                .setMimeType(new String[]{"text/plain", "application/vnd.google-apps.document"})
                .build(mGoogleApiClient);
        try {
            startIntentSenderForResult(intentSender, GDRIVE_REQUEST_CODE_OPENER, null, 0, 0, 0);
        } catch (IntentSender.SendIntentException e) {
            Log.w(TAG, "Unable to send intent", e);
        }
    }
}
 
Example #12
Source File: FileManager.java    From amiibo with GNU General Public License v2.0 6 votes vote down vote up
@DebugLog
private void createAmiiboFolder() {
    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle(AMIIBO_FOLDER).build();

    Drive.DriveApi.getRootFolder(_parent.getClient())
            .createFolder(_parent.getClient(), changeSet)
            .setResultCallback(new ResultCallback<DriveFolder.DriveFolderResult>() {
                @Override
                public void onResult(DriveFolder.DriveFolderResult driveFolderResult) {
                    if (driveFolderResult.getStatus().isSuccess()) {
                        app_folder_for_user = driveFolderResult.getDriveFolder();
                        listFiles();
                    } else {
                        app_folder_for_user = null;
                        _parent.onPushFinished();
                    }
                }
            });
}
 
Example #13
Source File: DriveFragment.java    From amiibo with GNU General Public License v2.0 6 votes vote down vote up
@DebugLog
@Override
public void onResume() {
    super.onResume();
    EventBus.getDefault().register(this);

    if (SyncService.getInstance() != null)
        mGoogleApiClient = SyncService.getInstance().getClient();

    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
        SyncService.getInstance().setGoogleApiClient(mGoogleApiClient);
    }

}
 
Example #14
Source File: MainActivity.java    From CumulusTV with MIT License 6 votes vote down vote up
@Override
public void onResult(DriveApi.DriveContentsResult result) {
    MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
            .setTitle("cumulustv_channels.json")
            .setDescription("JSON list of channels that can be imported using " +
                    "CumulusTV to view live streams")
            .setMimeType("application/json").build();
    IntentSender intentSender = Drive.DriveApi
            .newCreateFileActivityBuilder()
            .setActivityTitle("cumulustv_channels.json")
            .setInitialMetadata(metadataChangeSet)
            .setInitialDriveContents(result.getDriveContents())
            .build(CloudStorageProvider.getInstance().getClient());
    try {
        startIntentSenderForResult(
                intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        Log.w(TAG, "Unable to send intent", e);
    }
}
 
Example #15
Source File: DriveActivity.java    From biermacht with Apache License 2.0 6 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // Create the progress dialog view - displayed when connecting to Google APIs.
    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Connecting to Google APIs...");
    progressDialog.setIndeterminate(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setCancelable(false);

    // Create the connection driveClient.
    driveClient = new GoogleApiClient.Builder(this)
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_FILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
  }
 
Example #16
Source File: ActivityUtils.java    From CumulusTV with MIT License 6 votes vote down vote up
public static void createDriveData(Activity activity, GoogleApiClient gapi,
        final ResultCallback<DriveApi.DriveContentsResult> driveContentsCallback) {
    PermissionUtils.requestPermissionIfDisabled(activity,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
            activity.getString(R.string.permission_storage_rationale));
    if(gapi == null)
        gapi = mCloudStorageProvider.connect(activity);
    try {
        final GoogleApiClient finalGapi = gapi;
        new AlertDialog.Builder(activity)
                .setTitle(R.string.create_sync_file_title)
                .setMessage(R.string.create_sync_file_description)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Drive.DriveApi.newDriveContents(finalGapi)
                                .setResultCallback(driveContentsCallback);
                    }
                })
                .setNegativeButton(R.string.no, null)
                .show();
    } catch(Exception ignored) {
        Toast.makeText(activity, "Error creating drive data: " + ignored.getMessage(),
                Toast.LENGTH_SHORT).show();
    }
}
 
Example #17
Source File: LeanbackFragment.java    From CumulusTV with MIT License 6 votes vote down vote up
@Override
public void onResult(DriveApi.DriveContentsResult result) {
    MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
            .setTitle("cumulustv_channels.json")
            .setDescription("JSON list of channels that can be imported using CumulusTV to view live streams")
            .setMimeType("application/json").build();
    IntentSender intentSender = Drive.DriveApi
            .newCreateFileActivityBuilder()
            .setActivityTitle("cumulustv_channels.json")
            .setInitialMetadata(metadataChangeSet)
            .setInitialDriveContents(result.getDriveContents())
            .build(CloudStorageProvider.getInstance().getClient());
    try {
        mActivity.startIntentSenderForResult(
                intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        Log.w(TAG, "Unable to send intent", e);
    }
}
 
Example #18
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 #19
Source File: GameHelper.java    From ColorPhun with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
        builder.addApi(AppStateManager.API);
        builder.addScope(AppStateManager.SCOPE_APP_STATE);
    }

    if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
      builder.addScope(Drive.SCOPE_APPFOLDER);
      builder.addApi(Drive.API);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #20
Source File: GameHelper.java    From Onesearch with MIT License 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
        builder.addApi(AppStateManager.API);
        builder.addScope(AppStateManager.SCOPE_APP_STATE);
    }

    if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
      builder.addScope(Drive.SCOPE_APPFOLDER);
      builder.addApi(Drive.API);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #21
Source File: GameHelper.java    From FlappyCow with MIT License 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
      builder.addScope(Drive.SCOPE_APPFOLDER);
      builder.addApi(Drive.API);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #22
Source File: GameHelper.java    From cordova-google-play-games-services with MIT License 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }


    if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
      builder.addScope(Drive.SCOPE_APPFOLDER);
      builder.addApi(Drive.API);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #23
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 #24
Source File: FileManager.java    From amiibo with GNU General Public License v2.0 5 votes vote down vote up
@DebugLog
private void getAmiiboFolder() {
    Drive.DriveApi.getRootFolder(_parent.getClient())
            .listChildren(_parent.getClient())
            .setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
                @Override
                public void onResult(DriveApi.MetadataBufferResult metadataBufferResult) {
                    boolean found = false;
                    try {
                        List<Metadata> files = new ArrayList<>();
                        MetadataBuffer buffer = metadataBufferResult.getMetadataBuffer();
                        Metadata data;

                        for (int i = 0; i < buffer.getCount(); i++) {
                            data = buffer.get(i);
                            if (data.getTitle().equals(AMIIBO_FOLDER) && data.isFolder()
                                    && !data.isTrashed()) {
                                app_folder_for_user = Drive.DriveApi
                                        .getFolder(_parent.getClient(), data.getDriveId());
                                Log.d("FileManager", data.getDriveId() + " " + data.getTitle());
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    if (app_folder_for_user != null) {
                        listFiles();
                    } else {
                        createAmiiboFolder();
                    }
                }
            });
}
 
Example #25
Source File: CloudStorageProvider.java    From CumulusTV with MIT License 5 votes vote down vote up
public GoogleApiClient connect(Activity activity) {
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(activity)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addConnectionCallbacks((GoogleApiClient.ConnectionCallbacks) activity)
                .addOnConnectionFailedListener((GoogleApiClient.OnConnectionFailedListener)
                        activity)
                .build();
    }
    mGoogleApiClient.connect();
    return mGoogleApiClient;
}
 
Example #26
Source File: DriveSettingsManager.java    From CumulusTV with MIT License 5 votes vote down vote up
/**
 * Writes some data to a Google Drive file, this can get from a preference
 * @param driveId The id of the file to be written to
 * @param data The string of data that should be written
 */
public void writeToGoogleDrive(DriveId driveId, String data) {
    DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient, driveId);
    if (DEBUG) {
        Log.d(TAG, "Writing to " + driveId + " -> " + data);
    }
    new EditGoogleDriveAsyncTask(mContext).execute(file, data);
}
 
Example #27
Source File: ActivityUtils.java    From CumulusTV with MIT License 5 votes vote down vote up
public static void syncFile(Activity activity, GoogleApiClient gapi) {
    if (DEBUG) {
    Log.d(TAG, "About to sync a file");
    }
    if (gapi == null && mCloudStorageProvider.connect(activity) != null) {
        gapi = mCloudStorageProvider.connect(activity);
    } else if(mCloudStorageProvider.connect(activity) == null) {
        // Is not existent
        Toast.makeText(activity, "There is no Google Play Service", Toast.LENGTH_SHORT).show();
        return;
    }
    if (gapi.isConnected()) {
        IntentSender intentSender = Drive.DriveApi
                .newOpenFileActivityBuilder()
                .setMimeType(new String[]{"application/json", "text/*"})
                .build(gapi);
        try {
            if (DEBUG) {
                Log.d(TAG, "About to start activity");
            }
            activity.startIntentSenderForResult(intentSender, REQUEST_CODE_OPENER, null, 0, 0,
                    0);
            if (DEBUG) {
                Log.d(TAG, "Activity activated");
            }
        } catch (IntentSender.SendIntentException e) {
            if (DEBUG) {
                Log.w(TAG, "Unable to send intent", e);
            }
            e.printStackTrace();
        }
    } else {
        Toast.makeText(activity, R.string.toast_msg_wait_google_api_client,
                Toast.LENGTH_SHORT).show();
    }
}
 
Example #28
Source File: BaseDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the sign-in process and initializes the Drive client.
 */
private void signIn() {
    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 #29
Source File: VideoDetailsFragment.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate DetailsFragment");
    super.onCreate(savedInstanceState);

    prepareBackgroundManager();

    try {
        jsonChannel = new JsonChannel.Builder(getActivity().getIntent()
                .getStringExtra(EXTRA_JSON_CHANNEL))
                .build();
    } catch (JSONException e) {
        throw new IllegalArgumentException(e.getMessage());
    }

    if (jsonChannel != null) {
        setupAdapter();
        setupDetailsOverviewRow();
        setupDetailsOverviewRowPresenter();
        setupMovieListRowPresenter();
        updateBackground();
    } else {
        Intent intent = new Intent(getActivity(), MainActivity.class);
        startActivity(intent);
    }

    gapi = new GoogleApiClient.Builder(getActivity())
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_FILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    gapi.connect();
}
 
Example #30
Source File: MainActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the sign in process to get the current user and authorize access to Drive.
 */
private void signIn() {
    GoogleSignInOptions signInOptions =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestScopes(Drive.SCOPE_FILE)
                    .build();
    GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(this, signInOptions);
    startActivityForResult(googleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN);
}