简体   繁体   中英

Android Google Drive SDK upload files?

It is possible to upload file though Google Drive SDK? I've imported google play services as library and I can create only an empty file or a folder.

Drive.DriveApi.getRootFolder(mGoogleApiClient)
  .createFolder(mGoogleApiClient, changeSet)
  .setResultCallback(
  new ResultCallback<DriveFolder.DriveFolderResult>() {
    @Override
    public void onResult(
    DriveFolder.DriveFolderResult result) {
    if (!result.getStatus()
    .isSuccess()) {
    show("Error while trying to create the folder");
    return;
    }
  Log.d("info","Folder created");
}

But how I can upload a file or multiple to Google Drive programatically?

I've only used drive-sdk with python, so I don't know the details of uploading files using android. Anyway, the documentation provides a toturial in Java that shows you how to upload a file to Drive. It might help you with your request.

Using the 'Drive API for Android', you need to either:

1) newDriveContents(), THEN write to the DriveContents that you receive, THEN createFile() using that DriveContents.

2) createFile(), THEN get that file's DriveContents, THEN write to the DriveContents, then commit() the changes to that DriveContents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM