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.ReginFell:RxImagePicker:'
}
dependencies {
implementation("com.github.ReginFell:RxImagePicker:")
}
<dependency>
<groupId>com.github.ReginFell</groupId>
<artifactId>RxImagePicker</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.ReginFell" % "RxImagePicker" % ""
:dependencies [[com.github.ReginFell/RxImagePicker ""]]
An easy way to get image from Gallery or Camera with request runtime permission on Android M using RxJava
To use this library your minSdkVersion
must be >= 16.
In your build.gradle :
dependencies {
compile 'com.mlsdev.rximagepicker:library:1.3.1'
compile 'io.reactivex:rxjava:1.0.14'
}
RxImagePicker.with(context).requestImage(Sources.CAMERA).subscribe(new Action1<Uri>() {
@Override
public void call(Uri uri) {
//Get image by uri using one of image loading libraries. I use Glide in sample app.
}
});
Request multiple images on Android Api level 18+ :
RxImagePicker.with(context).requestMultipleImages().subscribe(new Action1<List<Uri>>() {
@Override
public void call(List<Uri> uris) {
//Get images by uris.
}
});
RxImagePicker.with(context).requestImage(Sources.GALLERY)
.flatMap(new Func1<Uri, Observable<Bitmap>>() {
@Override
public Observable<Bitmap> call(Uri uri) {
return RxImageConverters.uriToBitmap(context, uri);
}
})
.subscribe(new Action1<Bitmap>() {
@Override
public void call(Bitmap bitmap) {
// Do something with Bitmap
}
});
RxImagePicker.with(context).requestImage(Sources.GALLERY)
.flatMap(new Func1<Uri, Observable<File>>() {
@Override
public Observable<File> call(Uri uri) {
return RxImageConverters.uriToFile(context, uri, new File("YOUR FILE"));
}
})
.subscribe(new Action1<File>() {
@Override
public void call(File file) {
// 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!