0

I’m doing an application for Android (version 4.4), and I’m trying to select multiple files (.doc, .pdf) at the same time. The objective is to navigate through directories, select some desiderated files and return a list of these files. I’ve initially tried in this way, but the instruction Extra_Allow_Multiple doesn’t work: I can only select one file at a time.

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

So I’ve tried in this other way, but I’m not browsing in all directories of the device, only in specific ones (images/videos/audio…), and I can’t select multiple files for the same reason as before.

Intent intent = new Intent();
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

I’ve tried also other combinations, but often an error similar to this appears:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT (has extras) }

How can I select multiple files, possibly in a way alike to first method?

Dieghitus
  • 55
  • 3
  • 9

1 Answers1

0

Have you tried this?

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

I took this snippet of code from this StackOverflow question.

I am not very familiar with this functionality in Android, but you can apparently retrieve the files Uri with onActivityResult() if this helps any further.

Community
  • 1
  • 1
  • In this way startActivity opens directly the initial Activity of Dropbox, and I can't browse in the internal files of the device. Instead, with intent.setType(" * / * "); I see only specific folders (images, video, downloads) and I can only pick one file at a time, while I'm looking for a method that allows me multiple selection :) – Dieghitus Jul 15 '16 at 16:51
  • Ohh, I get it :D I made some research on developer.android.com, and found that Intent.EXTRA_ALLOW_MULTIPLE (true) makes it possible... but it seems you've already done that, have you tried a different file manager (ie: ES file explorer)? [Link to Android dev](https://developer.android.com/guide/components/intents-common.html#Storage) Also, here is an interesting SO [question](https://stackoverflow.com/questions/19068842/can-we-use-intent-extra-allow-multiple-for-older-versions-of-android-api-levels) – The Drummer from Kubuntu Jul 15 '16 at 17:03
  • Thanks - I've tried another time and Extra_Allow_Multiple works only with Action_get_content, just have to keep pressed the files to allow multiple selection. I've partially resolved my problem, only I can't navigate through the folders of my device: I only see specific folders with the default file manager. I've tried with File Explorer and two other programs, with which I can navigate as I want, but without the multiple selection allowed... – Dieghitus Jul 17 '16 at 19:08