Skip to content

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.

Notifications You must be signed in to change notification settings

MohdShamweel/MultipleImageSelect

Repository files navigation

MultipleImageSelect

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.

Lib_1 Lib_2 Lib_3 vid_lib_small

Installation

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'
  }

Usage

There are two ways to get the Images with the field imageData.Uri

  1. URI -> External Storage Image Uri's
  2. PATH -> 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.

Depending on @INTENT_GET_URI the result could be either Uri or 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)

Start the library intent

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)

Handle selected images

  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
              }       
        }
    }

Example:

To know more about implementation please checkout the Sample App

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

About

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.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages