Select multiple files with Intent.ACTION_GET_CONTENT

I am trying to select multiple files with Intent, but it seems like I'm missing something.
I create an Intent.ACTION_GET_CONTENT Intent, add Intent.EXTRA_ALLOW_MULTIPLE as an extra in the file (seems perfect for the purpose) and create a selector (optional) that selects the application that should be able to select multiple files and return them.

The problem is that I can only select one file.

I tried several file explorers. This is API 18 (4.3).

ACTIVITY_CHOOSE_FILE = 1; //global constant Button btn = (Button) this.findViewById(R.id.btnGetFiles); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent chooseFile; Intent intent; chooseFile = new Intent(Intent.ACTION_GET_CONTENT); chooseFile.setType("file/*"); chooseFile.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); intent = Intent.createChooser(chooseFile, "Choose a file"); startActivityForResult(intent, ACTIVITY_CHOOSE_FILE); } }); 

I also added this to the manifest (it had the same functionality before adding it):

  <intent-filter> <action android:name="android.intent.action.GET_CONTENT" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> 

Why can't I select multiple files?
(To clarify: the problem is not that several files are not returned - I cannot select more than one file)

+8
android android-intent
source share
3 answers

Why can't I select multiple files?

Presumably, the implementation of "an application that should be able to select multiple files and return them" did not implement support for EXTRA_ALLOW_MULTIPLE . Contact them and request this feature.

+3
source share

I have the same problem and ACTION_OPEN_DOCUMENT worked for me.

 public void selectImages() { Intent intent = new Intent(); intent.setType("image/*"); intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, your_initial_uri); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); intent.setAction(Intent.ACTION_OPEN_DOCUMENT); startActivityForResult(intent, 1); } public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if(resultCode == RESULT_OK) { for(int i = 0; i < data.getClipData().getItemCount(); i++) { Uri uri = data.getClipData().getItemAt(i).getUri(); System.out.println("image" + i + "=" + uri.toString()); } } } } 
0
source share

I have the same problem. Here is my solution.

Java:

 public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data) if(requestCode == PICKFILE_RESULT_CODE) { if(null != data) { // checking empty selection if(null != data.getClipData()) { // checking multiple selection or not for(int i = 0; i < data.getClipData().getItemCount(); i++) { Uri uri = data.getClipData().getItemAt(i).getUri(); } } else { Uri uri = data.getData(); } } } } 

Kotlin:

 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { PICKFILE_RESULT_CODE -> if (resultCode === Activity.RESULT_OK) { if (null != data) { if (null !=data.clipData) { for (i in 0 until data.clipData.itemCount) { val uri = data.clipData.getItemAt(i).uri dumpImageMetaData(uri) } } else { val uri = data.data dumpImageMetaData(uri) } } } } } 
0
source share

All Articles