https://kotlinlang.org logo
s

Shakil Karim

03/30/2021, 6:54 PM
Hi All, Is there any reliable Image picking lib which support android 11 and other use cases, It is super common task and almost 99 percent of stackOverflow answers are wrong. I hope at some point there will be an Android X lib for picking Images/Video/Documents @Ian Lake Please can you suggest reliable way to achieve it across different devices and Android Versions.
s

Shakil Karim

03/30/2021, 7:21 PM
@Ian Lake Thanks, do i need to copy the local file data with ContentResolver.openInputStream to select the file? or is it just for Uri which is remote like Google drive?
i

Ian Lake

03/30/2021, 10:07 PM
If you are using
GetContent
like the docs use as an example (https://developer.android.com/training/basics/intents/result#register), then you can call
ContentResolver.openInputStream()
on every returned Uri on every API level and it just works
s

Samir Basnet

03/31/2021, 7:43 AM
That content resolver method will fail for certain lower versions or some OEMs . I have tried and no way is there that you can handle image pick using single method supporting android 5+
1
s

Shakil Karim

03/31/2021, 8:07 AM
@Ian Lake Yeah I agree with @Samir Basnet it's much more complicated than just a single method ContentResolver.openInputStream(). permissions, storage availability, memory conditions etc. I still thinks an AndroidX lib/APIs which handle all those cases and provide reliable way to fetch File will be great.
s

Samir Basnet

03/31/2021, 8:12 AM
Yup believe me when i say this i have searched entire internet for handling file pick using single method(And i am excluding permission and space availability checks here) and it does not exist. We have to use PathUtils class available all over stackoverflow and github gist, that contains a whole ton of methods to handle this process for different versions of androids in different way. And what is crazy is that even that PathUtils is not enough , i had to add some more logic on top of that PathUtil class as it was not working in some Xioami or Samsung devices. If it was as easy as using content resolver then why are there so much library just to help us select a file?
i

Ian Lake

03/31/2021, 2:37 PM
Do you know why you see StackOverflow questions around "can't attach file" for Gmail or Whatsapp when people are doing it wrong (i.e., not using FileProvider, etc.)? It's because those apps are using straight up
ContentResolver.openInputStream
and that's it because that's the correct thing to do when reading content from an incoming Uri and the only correct thing to do with an incoming Uri