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 >= 14.
In your build.gradle :
dependencies {
compile 'com.mlsdev.rximagepicker:library:1.1.7'
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.
}
});
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
}
});
- Sergey Glebov (frederikos), MLSDev
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!