im triying to use an image picker so I can open the gallery and choose a pic for the user profile.
Apparently the built-in image picker works only on Android 13 (API 33) so in order to add this feature i have to add this library.
The first step is not clear to me:
Gradle dependency:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
implementation 'com.github.dhaval2404:imagepicker:2.1'
If you are yet to Migrate on AndroidX, Use support build artifact:
implementation 'com.github.dhaval2404:imagepicker-support:1.7.1'
I added the second section code in build.gradle (App level) in order to make it work but when i try to implement it in my code I get this message
Adding the dependency suggested by Android Studio does not solve the problem, 99% I’m missing something.
2
Answers
When you add a new library reference in your app/bundle.gradle file:
be sure to run Gradle sync:
Then to need to add
import
in the java/kotlin source code:just like in the sample of that library
Just in case you didn’t know, you can already open a file picker that only displays photos – the Photo Picker thing is a new feature in Android 13 (which isn’t even released yet), so this is still the standard way to do it!
There’s actually two versions at the link – one uses
GET_CONTENT
which copies the image, the other usesOPEN_DOCUMENT
which gives you a URI pointing to the existing file on disk. Read the descriptions to see which works best for whatever you’re doing.So yeah, if you want something that looks like a plain photo gallery, you’ll either need the new picker or a library that does similar. If you just want to let the user load an image though, the standard document browser should be familiar