In my Android app I would like the user to open a Google Sheets document to import data from it into the app database.
-
It's easy to select a file with
ACTION_GET_CONTENT/ACTION_OPEN_DOCUMENTand with MIME filterapplication/vnd.google-apps.spreadsheet. (It will be a virtual file.) -
It's also easy to get the content of a Google Sheets document with the Google Sheets API based on the Drive filed id (with user-granted
spreadsheets.readonlyscope):
Sheets.Builder(transport, jsonFactory, appCredential)
.build()
.spreadsheets()
.get(fileid)
.execute()
But the first step returns the Uri of the file on the device, and the second step requires the file id of the Drive file.
How can I determine the second from the first?
The only poor solution I found was to use the Google Drive API: I search the Sheets file with its name I got from the intent, and I get the id of it... It requires the drive.metadata.readonly scope, which is a restricted scope, and doh... it's not a viable solution anyway...
I can download a pdf from the uri of the virtual file, but it's not suitable for importing data.
If anyone knows the answer, a thousand thanks for it!
from Is there any way to get Google Sheets fileid from file picker intent?
No comments:
Post a Comment