Here is the Demo for the PhotoPicker in All Android Versions
I have added other pickers as well(pdf,doc,video,pictures).
I have tested with multiple scenarios , here is the scenario list
- Android 8 to 13 versions
- Also Add the Single Photo and Multiple Photo Selection
- Single Photo Selection Working on All Android Versions
- Multiple Photo Selection will work from Android 11 to Android 13.
- Multiple Photo Selection below Android 11 we have to use clipdata the old way.
Here how to use library in your project follow below steps .
- In your gradle(app) add below line
dependencies{
implementation 'com.github.ParthLotia:FilePicker:Tag'
}
Replace your Tag with current version 1.0.8
- In your project level gradle add below line
repositories {
google()
mavenCentral()
maven { url "https://www.jitpack.io" }
}
- Add below code in your activity/fragment
In on create add below lines
btn_upload_pick.setOnClickListener {
val mimeType = "*/*"
/*Single Document Picker*/
// Image , Video , PDF , DOC , DOCX
pickMedia.launch(
arrayOf(mimeType)
)
}
Out side on create add below lines of code
private val pickMedia =
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
if (uri != null) {
val file = FileUriUtils.getRealPath(this, uri)?.let { File(it) }
if (FileUriUtils.checkExtensionFile(file)) {
img_pick.setImageURI(uri)
} else {
img_pick.setImageBitmap(
FileUtil.getThumbnail(
file,
uri,
context = applicationContext
)
)
}
} else {
Log.d("PhotoPicker", "No media selected")
}
}
Here img_pick is an Imageview to display the file you have selected .