Reputation: 21
I'm working with Google Drive API V3 to create folder with android app.
After creation the file Id is saved to shared pref - to use and append it later. File is saved as User info, and not App Info, so the user can change it from the Drive. It's possible that folder is trashed or deleted completely - and if it is, I want to create new folder.
According to this explanation about searching files I can use files.list - but this will return all the files. and I need only specific file (if it exists)
when fetching a list - I can see the value of trashed (true / false) like this:
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()));
}
}
In my code - mDriveFolderId
is the String with the ID of the folder after creating it - taken from "file.getId()"
.
I've tried to use -
File checkFileTrashed = mDriveService.files()
.get(mDriveFolderId)
.setFields("files(trashed)")
.execute();
This returns exception:
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"
}
Thanks a lot!!
Upvotes: 1
Views: 936
Reputation: 21
Found the structure for SetFields() - to identify if file is Trashed
File checkFileTrashed = mDriveService.files()
.get(mDriveFolderId)
.setFields("trashed")
.execute();
you can use this reference from Google Drive API
Once a file is Deleted - you'll get IOException
,
with "message" : "File not found: <the fileId >
"
you can catch it and handle the logic (create new folder, send message to user, etc...)
Upvotes: 1