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 16 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 16.
- 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.9
- 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 . For Jetpack Compose Button(onClick = { singleFilePickerLauncher.launch(arrayOf("*/*")) }) { Text(text = "Choose File") } val singleFilePickerLauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.OpenDocument(), onResult = { uri -> if (uri != null) { file = FileUriUtils.getRealPath(this, uri)?.let { File(it) } if (FileUriUtils.checkExtensionFile(file)) { selectedSingleImageUri.value = uri selectedSingleImageUriThumbnail.value = null } else { selectedSingleImageUri.value = null Log.e("uri", "PLAndroid" + uri) selectedSingleImageUriThumbnail.value = uri } } } ) selectedSingleImageUri.value.let { if (it != null) { AsyncImage(model = it, contentDescription = "") } } Here AsyncImage is an ImageView to display the file you have selected .