Android Drive API V3 - 如何知道文件是否已删除?

Android Drive API V3 - How to know if file is Trashed or deleted?

我正在使用 Google Drive API V3 来创建带有 android 应用程序的文件夹。

创建后,文件 ID 将保存到共享首选项 - 以便稍后使用和追加。 文件保存为用户信息,而不是应用程序信息,因此用户可以从驱动器中更改它。 文件夹可能已被删除或完全删除 - 如果是,我想创建新文件夹。

根据这个 explanation about searching files 我可以使用 files.list - 但是这将 return 所有文件。 我只需要特定文件(如果存在)

获取列表时 - 我可以看到 trashed 的值(真/假) 像这样:

List<String> fileInfo = new ArrayList<String>();
FileList result = mDriveServiceForTrash.files().list()
         .setPageSize(100)
         .setFields("nextPageToken, files(id, name,trashed)")
         .execute();
List<File> files = result.getFiles();

if (files != null) {
    for (File file : files) {
        fileInfo.add(String.format("%s (%s) trashed =%s\n",
            file.getName(), file.getId(),file.getTrashed()));
    }
}

在我的代码中 - mDriveFolderId 是创建后带有文件夹 ID 的字符串 - 取自 "file.getId()"

我试过使用 -

File checkFileTrashed = mDriveService.files()
    .get(mDriveFolderId)
    .setFields("files(trashed)")
    .execute();

这个 return 异常:

error = 400 Bad Request {
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "location" : "fields",
    "locationType" : "parameter",
    "message" : "Invalid field selection files",
    "reason" : "invalidParameter"
  } ],
  "message" : "Invalid field selection files"
}
  1. 谁能告诉我解决方案以获得价值 具体文件?
  2. setFields() 的结构是什么?

非常感谢!!

找到 SetFields() 的结构 - 确定文件是否 Trashed

File checkFileTrashed = mDriveService.files()
    .get(mDriveFolderId)
    .setFields("trashed")
    .execute();

你可以使用这个reference from Google Drive API

一旦文件被删除 - 你会得到IOException"message" : "File not found: <the fileId >"

您可以捕获它并处理逻辑(创建新文件夹、向用户发送消息等...)