1

My Android app needs to share a file of the user's choice from Google Drive and obtain the link. The v3 Google Drive API doesn't provide its own file pickers on Android, so I'm using the system file picker.

The problem is that com.google.api.services.drive.Drive.Permissions#create requires a fileID as the first parameter, whereas what the system file picker gives me is a content: URI. How do I look up the fileID corresponding to this URI? When I try DocumentsContract.getDocumentId(url) or DocumentsContract.getDocumentId(url).split("doc=encoded=")[1] (or one of the ContentResolver ID columns) as the URI-to-ID function, I get a 404. When I try this answer, the regex doesn't match anything.

An example of a content: URI I need to translate is:

content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3Dencoded%3DBEskNs6jf7jS24J%2FMnNdnr7fDrih03xNetfcCUsggemjSmpiWBC5

I've tried searching for the name and mimetype obtained from the ContentResolver, but this has 2 issues: it requires files.metadata.readonly permission, and it doesn't help if there's a file of the same name in a different folder of the same user's Drive.

Pr0methean
  • 303
  • 4
  • 14
  • The Google Picker API is not part of the Google Drive API. It is a separate API that you can and should use. see https://developers.google.com/drive/api/v3/picker – GroovyDotCom Aug 19 '19 at 17:52

1 Answers1

2

In theory the Javascript based Google Picker API could be run in a webview.

see https://developers.google.com/drive/api/v3/picker

UPDATE: I see that others who have tried this approach have experienced problems such as sizing to fit phone screens, etc. so this is not a good approach.

Google Drive Picker (JavaScript) not mobile friendly / responsive

GroovyDotCom
  • 1,304
  • 2
  • 15
  • 29
  • 1
    That picker is written in HTML and JavaScript, and isn't intended for Android according to the note at the top. How do I even use it inside my Android app? – Pr0methean Aug 19 '19 at 20:32
  • 1
    I had thought that it would not be difficult to launch in a WebView but I see that others had sizing issues with this approach. https://stackoverflow.com/questions/31918206/google-drive-picker-javascript-not-mobile-friendly-responsive I'll edit my answer. – GroovyDotCom Aug 19 '19 at 22:10
  • Is there version of this that's for Java or Kotlin? – Fred Ross-Perry Aug 16 '22 at 22:49