17

While the Google Drive Android API, an API separate from the Google Drive Rest API, does contain a file picker, the Google Drive Android API is not integrated with all the features of the Google Drive Rest API, such as exporting Google Docs files to a different format. Although there is a Google Drive Rest API file picker available for web applications, I have not found one for Android applications. Does anyone know the best way to create a file picker for the user to choose files from their Google Drive account by using the Google Drive Rest API?

3
  • did you find the solution for this? Did you try using the Drive REST Api? Commented Jun 9, 2017 at 11:34
  • @Capt I used the Drive Rest API, but as a result, the user now has to give permission to access files from their account twice. Commented Jun 10, 2017 at 15:46
  • 3
    I would love to see a good answer for this, now that Google just announced that they are deprecating the Google Drive Android API and forcing everyone to use the Google Drive REST API. Commented Dec 16, 2018 at 2:39

2 Answers 2

1

The file picker is implemented as an Intent and allows you develop a native Android user experience with just a couple lines of code. This following code snippet launches the picker and allows the user to select a text file:

// Launch user interface and allow user to select file
IntentSender i = Drive.DriveApi
.newOpenFileActivityBuilder()
.setMimeType(new String[] { “text/plain” })
.build(mGoogleApiClient);
startIntentSenderForResult(i, REQ_CODE_OPEN, null, 0, 0, 0);

The result is provided in the onActivityResult callback as usual.

You may be wondering how the Google Drive Android API relates to the Storage Access Framework.

The Storage Access Framework is a generic client API that works with multiple storage providers, including cloud-based and local file systems. While apps can use files stored on Google Drive using this generic framework, the Google Drive API offers specialized functionality for interacting with files stored on Google Drive — including access to metadata and sharing features. Additionally, as part of Google Play services the Google Drive APIs are supported on devices running Android 2.3 Gingerbread and above.

Sign up to request clarification or add additional context in comments.

4 Comments

This answer demonstrates the problem I have with using the Google Drive API for Android: I can only open non-Google Docs files. My goal is to allow users to open Google Docs files and have them converted to text files in the background.
The question is about the Drive Rest API, but the answer provides solution for Drive Android API which is working on files are created by the app only
This has a crippling limitation: it only outputs content URIs, and not the file IDs required by other parts of the Drive API (e.g. to get a sharing link).
Not good! This answer uses the Google Drive Api, but the question is about the new Drive rest api
0

A lot has changed since the last answer has been written to this question. Google provided only web file picker and it does not work anymore in the webview on mobile. So, if you would face this issue, the best place to find the latest updates for it, I'd recommend is here - https://issuetracker.google.com/issues/322267485

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.