Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android open file using Google Drive with ACTION_GET_CONTENT

I am trying to open a file from Google Drive in my android app. Here is what I currently have.

        Intent importIntent = new Intent(Intent.ACTION_GET_CONTENT);
        importIntent.setType("file/*");
        startActivityForResult(importIntent, ACTIVITY_REQUEST_CODE_IMPORT);

This opens a "Open From" dialog which allows to select files using Google Drive, Downloads and my file browser. I can select files using my file browser without a problem. But Google Drive doesn't allow me to select files. All files shown in Google Drive are grayed out and not selectable. Same happens when I try to select using Downloads.

How can I resolve this? if I use importIntent.setType("*/*"), Google Drive allows to select files, but several other options including Contacts, Images appear in "Open From" dialog which I do not want.

Thanks

like image 722
Lahiru Chandima Avatar asked Nov 10 '22 23:11

Lahiru Chandima


1 Answers

You have to set a more specific MIME type or a list of them, but you have to keep in mind that the ACTION_GET_CONTENT intent won't work with the latest Google Drive version starting from Android Kitkat. In order to get files from Drive you have to use the Google Drive API or use the storage access framework (SAF). Using SAF however it could be not what you want because it allows the user select other sources and not only Drive.

like image 132
greywolf82 Avatar answered Nov 14 '22 22:11

greywolf82