Sunday, 12 September 2021

Is there any way to get Google Sheets fileid from file picker intent?

In my Android app I would like the user to open a Google Sheets document to import data from it into the app database.

  1. It's easy to select a file with ACTION_GET_CONTENT / ACTION_OPEN_DOCUMENT and with MIME filter application/vnd.google-apps.spreadsheet. (It will be a virtual file.)

  2. 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.readonly scope):

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