简体   繁体   English

Android Google Drive SDK上传文件?

[英]Android Google Drive SDK upload files?

It is possible to upload file though Google Drive SDK? 是否可以通过Google Drive SDK上传文件? I've imported google play services as library and I can create only an empty file or a folder. 我已将Google Play服务导入为库,并且只能创建一个空文件或文件夹。

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? 但是,如何以编程方式将一个或多个文件上传到Google云端硬盘?

I've only used drive-sdk with python, so I don't know the details of uploading files using android. 我只在python中使用drive-sdk,所以我不知道使用android上传文件的详细信息。 Anyway, the documentation provides a toturial in Java that shows you how to upload a file to Drive. 无论如何, 文档提供了Java实用知识,向您展示了如何将文件上传到云端硬盘。 It might help you with your request. 它可能会帮助您解决您的请求。

Using the 'Drive API for Android', you need to either: 使用“ Android驱动器API”时,您需要执行以下任一操作:

1) newDriveContents(), THEN write to the DriveContents that you receive, THEN createFile() using that DriveContents. 1)newDriveContents(),然后将其写入您收到的DriveContents,然后使用该DriveContents写入createFile()。

2) createFile(), THEN get that file's DriveContents, THEN write to the DriveContents, then commit() the changes to that DriveContents. 2)createFile(),然后获取该文件的DriveContents,然后将其写入DriveContents,然后commit()对该DriveContents进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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