As Daniel stated, there is no possibility with Intent.EXTRA_ALLOW_MULTIPLE. An alternative though, is using the MultipleImageSelect library. Not only can you select multiple images, but the extra ability to set a limit on images selected by the user.
Check out the repository or a sample.
STEPS:
Step 1:
Add MultipleImageSelect library, together with jitpack.io to your build.gradle like this:
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
implementation 'com.github.darsh2:MultipleImageSelect:v0.0.4'
}
Step 2:
In project's AndroidManifest.xml, add the following under application node:
<activity
android:name="com.darsh.multipleimageselect.activities.AlbumSelectActivity"
android:theme="@style/MultipleImageSelectTheme">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Step 3:
In the activity from where you want to call image selector, create Intent as follows:
mSelectImagesBtn.setOnClickListener(view -> {
Intent intent = new Intent(ListingImages.this, AlbumSelectActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_LIMIT, 3); //set desired image limit here
startActivityForResult(intent, Constants.REQUEST_CODE);
});
Step 4:
and override onActivityResult like this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data !=null) {
ArrayList<Image> images =data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
imagePathList.clear();
StringBuffer stringBuffer = new StringBuffer();
//loop to retrieve the paths of each image and display to TextView
for (int i = 0; i < images.size(); i++) {
stringBuffer.append(images.get(i).path + "\n");
}
textView.setText(stringBuffer.toString());
}
}
DONE
Alternatively,
If you're using an Adapter to inflate images to display, you can instead have this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data != null) {
ArrayList<Image> images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
imagePathList.clear();
for (int i = 0; i < images.size(); i++) {
imagePathList.add(images.get(i).path);
}
imageAdapter.notifyDataSetChanged();
}
}
Within ImageAdapter, display images to populate recyclerView, like follows:
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
String path = imagePathList.get(position);
Picasso.with(mContext)
.load(new File(path))
.placeholder(R.drawable.ic_house_placeholder)
.into(holder.image);
}