Android Multiple Image Selector Library with features to either get URI's of the selected Images present at the External Storage or get their paths after copying the selected images to their specific Scoped Storage directory.
Add the following maven repository in root build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the following dependency in app build.gradle:
dependencies {
implementation 'com.github.MohdShamweel:MultipleImageSelect:0.5'
}
There are two ways to get the Images with the field imageData.Uri
URI
-> External Storage Image Uri'sPATH
-> Scoped Storage Directory Path
As of SDK 29, we can't access image by path on external Storage except by MANAGE_EXTERNAL_STORAGE
permission, so to get the paths of the Selected Images, the images will be copied to the app's scoped directory and from there they can be accessed via path.
intent.putExtra(Constants.INTENT_GET_URI, true)
Result -> URI
access by (imageData.Uri)
intent.putExtra(Constants.INTENT_GET_URI, false)
Result-> URI
-> files copy to android/data/<app-package-name>/files/Pictures/Sent
-> Path
access by (imageData.Uri)
val intent = Intent(this, MultipleImageSelectActivity::class.java)
intent.putExtra(Constants.INTENT_EXTRA_LIMIT, 10) //Max number of Images that can be selected
intent.putExtra(Constants.INTENT_GET_URI, false)
startActivityForResult(intent, Constants.REQUEST_CODE)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data != null){
val selectedImagesData : ArrayList<ImageData> = data.getSerializableExtra(Constants.INTENT_EXTRA_IMAGES) as ArrayList<ImageData>
for (imageData in selectedImagesData){
var path: String = imageData.Uri
}
}
}
To know more about implementation please checkout the Sample App
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.