Though not through an Intent but I have found a good library project by droidninja that enables one to browse through doc files or images stored locally in a single go.
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
Insert this in your app.gradle file
compile 'com.droidninja:filepicker:1.0.6'
then call this below given function to have a material themed dialog box which will give one an option to choose whether to choose an images or group or same with docs
private void showFileChooser() {
new MaterialStyledDialog.Builder(getActivity())
.setTitle("Upload Documents")
.setDescription("Upload single or multiple documents in a single attempt now, maximum being 5.\n \nChoose between Images option or PDF's option now. \n")
//.setStyle(Style.HEADER_WITH_ICON)
.setHeaderColor(R.color.colorPrimary)
.withDialogAnimation(true)
.setIcon(R.drawable.ic_pdf)
.setCancelable(true)
.autoDismiss(false)
.setPositiveText(R.string.images)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
FilePickerBuilder.getInstance().setMaxCount(5)
.setSelectedFiles(selectedPhotos)
.setActivityTheme(R.style.AppTheme)
.pickPhoto(getActivity());
}
})
.setNeutralText(R.string.pdf)
.onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
FilePickerBuilder.getInstance().setMaxCount(5)
.setSelectedFiles(filePaths)
.setActivityTheme(R.style.AppTheme)
.pickDocument(getActivity());
}
})
.show();
}
For this dialog box though, you need to have in gradle file
compile com.github.javiersantos:MaterialStyledDialogs:2.0'
finally, onActivityResult() will be called to extract the result something like this
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FilePickerConst.REQUEST_CODE_PHOTO:
if (resultCode == Activity.RESULT_OK && data != null) {
selectedPhotos = new ArrayList<>();
selectedPhotos.addAll(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_PHOTOS));
}
break;
case FilePickerConst.REQUEST_CODE_DOC:
if (resultCode == Activity.RESULT_OK && data != null) {
filePaths = new ArrayList<>();
filePaths.addAll(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_DOCS));
}
break;
}
}
AppTheme
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>