Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.MLSDev:RxImagePicker:'
}
dependencies {
implementation("com.github.MLSDev:RxImagePicker:")
}
<dependency>
<groupId>com.github.MLSDev</groupId>
<artifactId>RxImagePicker</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.MLSDev" % "RxImagePicker" % ""
:dependencies [[com.github.MLSDev/RxImagePicker ""]]
An easy way to get image from Gallery or Camera with request runtime permission on Android M using RxJava2
To use this library your minSdkVersion
must be >= 16.
In your build.gradle :
dependencies {
implementation 'com.mlsdev.rximagepicker:library:2.2.1'
}
RxImagePicker.with(supportFragmentManager).requestImage(Sources.CAMERA).subscribe {
//Get image by uri using one of image loading libraries. I use Glide in sample app.
}
Request image from gallery :
RxImagePicker.with(supportFragmentManager).requestImage(Sources.GALLERY).subscribe {
}
Request image from documents :
RxImagePicker.with(supportFragmentManager).requestImage(Sources.DOCUMENTS).subscribe {
}
Use android chooser to get image :
RxImagePicker.with(supportFragmentManager).requestImage(Sources.CHOOSER, "Chooser title").subscribe {
}
Request multiple images on Android Api level 18+ :
RxImagePicker.with(supportFragmentManager).requestMultipleImages().subscribe {
//Get images by uris.
}
RxImagePicker.with(context).requestImage(Sources.GALLERY)
.flatMap(new Function<Uri, ObservableSource<Bitmap>>() {
@Override
public ObservableSource<Bitmap> apply(@NonNull Uri uri) throws Exception {
return RxImageConverters.uriToBitmap(getContext(), uri);
}
}).subscribe(new Consumer<Bitmap>() {
@Override
public void accept(@NonNull Bitmap bitmap) throws Exception {
// Do something with Bitmap
}
});
RxImagePicker.with(context).requestImage(Sources.GALLERY)
.flatMap(new Function<Uri, ObservableSource<File>>() {
@Override
public ObservableSource<File> apply(@NonNull Uri uri) throws Exception {
return RxImageConverters.uriToFile(getContext(), uri, new File("YOUR FILE"));
}
}).subscribe(new Consumer<File>() {
@Override
public void accept(@NonNull File file) throws Exception {
// Do something with your file copy
}
});
RxImagePicker is released under the MIT license. See LICENSE for details.
RxImagePicker is maintained by MLSDev, Inc. We specialize in providing all-in-one solution in mobile and web development. Our team follows Lean principles and works according to agile methodologies to deliver the best results reducing the budget for development and its timeline.
Find out more here and don't hesitate to contact us!