I'm trying to select multiple files with an Intent, but it seems like I'm missing on something.
I create an Intent.ACTION_GET_CONTENT Intent, put Intent.EXTRA_ALLOW_MULTIPLE as extra in
(it seems to perfectly fit the purpose) and create a chooser (optional), which chooses the application that should be able to pick multiple files and return them.
The Problem is that I can only pick a single file.
I tried multiple file explorers. It's 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 choose multiple files?
(For clarification: the problem is not, that multiple files aren't returned - I can't choose more than 1 file)
To select multiple files press on as many files as you want to select and check marks will appear over all of the selected files. OR you press the More options menu icon in the upper right corner of the screen and press Select.
A common intent action is ACTION_VIEW, which you use when you have some information that an activity can show to the user, such as a photo to view in a gallery app, or an address to view in a map app. You can specify the action for an intent in the intent constructor, or with the setAction() method.
An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object.
To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent.
I got same issue. Here 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) } } } } }
Why can't I choose multiple files?
Presumably, the implemeters of "the application that should be able to pick multiple files and return them" have not implemented EXTRA_ALLOW_MULTIPLE
support. Contact them and request this feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With