Search code examples
androidandroid-intentandroid-activitygoogle-drive-apiandroid-package-managers

How to get Google Drive to show with queryIntentActivities()?


In our app we're trying to get files from other file storage apps. So for example, open our app, start app chooser, select dropbox, select file, opens file in our app.

I've set this intent to try and invoke other apps:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PackageManager packageManager = getPackageManager();
List activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

The important part is queryIntentActivities, we're using the list of apps this returns to display what apps our users can choose. Apps like dropbox and Microsoft OneDrive show up no problem, but I Google Drive never shows up.

What do I need to set in my intent to have Google Drive be returned with queryIntentActivities?


Solution

  • On Android KitKat (API 19) and higher devices, apps can use the Storage Access Framework and build a DocumentsProvider. In those cases, the system UI is providing the UI when you call startActivity() with an ACTION_GET_CONTENT Intent - apps are not required to implement their own UI nor have an Activity that directly handles GET_CONTENT.

    As the system UI provides access to both apps using the Storage Access Framework and legacy apps that only provide a GET_CONTENT Activity, you should not have your own app chooser and instead just directly execute the ACTION_GET_CONTENT Intent and it'll work with all apps (and allow users to select files from multiple DocumentsProviders rather than only from a single app if you have the EXTRA_ALLOW_MULTIPLE flag set).