M
M
Mykhailo D2016-02-09 18:37:50
Android
Mykhailo D, 2016-02-09 18:37:50

How to sync local folder via Google Drive Android API?

Hi!
People, tell a newbie with the Google Drive Android API, namely with synchronizing a folder on an android device (for example / storage / sdcard0 / mySyncFolder) and with Google drive. I apologize for the possible incorrectness of the question :)
I saw a bunch of examples here https://github.com/googledrive/android-demos , but I did not see such an implementation.
That is, the task is this, I want to upload the files to a folder on the SD, and my application will already upload them to the drive (without any dialog boxes and confirmations, in the background), having previously passed authentication and authorization, implemented on the same examples from the git. Push on parvil thoughts, or poke your nose where to look.
Here is a code snippet:

public class CreateFileInAppFolderActivity extends BaseDemoActivity {

    @Override
    public void onConnected(Bundle connectionHint) {
        super.onConnected(connectionHint);
        // create new contents resource
        Drive.DriveApi.newDriveContents(getGoogleApiClient())
                .setResultCallback(driveContentsCallback);
    }

    // [START drive_contents_callback]
    final private ResultCallback<DriveContentsResult> driveContentsCallback =
            new ResultCallback<DriveContentsResult>() {
        @Override
        public void onResult(DriveContentsResult result) {
            if (!result.getStatus().isSuccess()) {
                showMessage("Error while trying to create new file contents");
                return;
            }

            MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                    .setTitle("appconfig.txt")
                    .setMimeType("text/plain")
                    .build();
            Drive.DriveApi.getAppFolder(getGoogleApiClient())
                    .createFile(getGoogleApiClient(), changeSet, result.getDriveContents())
                    .setResultCallback(fileCallback);
        }
    };
    // [END drive_contents_callback]

    final private ResultCallback<DriveFileResult> fileCallback = new
            ResultCallback<DriveFileResult>() {
        @Override
        public void onResult(DriveFileResult result) {
            if (!result.getStatus().isSuccess()) {
                showMessage("Error while trying to create the file");
                return;
            }
            showMessage("Created a file in App Folder: "
                    + result.getDriveFile().getDriveId());
        }
    };
}

tell me what the changeSet object does ?
Thanks to!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question