Media Picker is an Android Libary that lets you to select multiple images, video or voice for Android 4.1 (API 16) +. You can report any issue on issues page. Note: If you speak Arabic, you can submit issues with Arabic language and I will check them. :)
This build 2.x.x
will break backward compatibility and there are a lot of changes to improve the performance and fix a lot of Leak memory issues, So please read below document carefully.
Maven
<dependency>
<groupId>net.alhazmy13.MediaPicker</groupId>
<artifactId>libary</artifactId>
<version>2.2.5</version>
</dependency>
Gradle
dependencies {
compile 'net.alhazmy13.MediaPicker:libary:2.2.5'
}
After adding the library, you need to:
- Create an object from
ImagePicker
- Override
onActivityResult
to receive the path of image.
You will need to create a new instance of ImagePicker
. Once the instance are configured, you can call build()
.
new ImagePicker.Builder(MainActivity.this)
.mode(ImagePicker.Mode.CAMERA_AND_GALLERY)
.compressLevel(ImagePicker.ComperesLevel.MEDIUM)
.directory(ImagePicker.Directory.DEFAULT)
.extension(ImagePicker.Extension.PNG)
.scale(600, 600)
.allowMultipleImages(false)
.enableDebuggingMode(true)
.build();
In order to receive the path of image, you will need to override onActivityResult
.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ImagePicker.IMAGE_PICKER_REQUEST_CODE && resultCode == RESULT_OK) {
List<String> mPaths = (List<String>) data.getSerializableExtra(ImagePicker.EXTRA_IMAGE_PATH);
//Your Code
}
}
mode
to select the mode, you can choose one of theseCAMERA
,GALLERY
orCAMERA_AND_GALLERY
.mode(ImagePicker.Mode.CAMERA)
extension
You can change the extension of image toPNG
orJPG
.extension(ImagePicker.Extension.PNG)
compressLevel
You can change the quality of image with three different levelsHARD
,MEDIUM
,SOFT
orNONE
.compressLevel(ImagePicker.ComperesLevel.MEDIUM)
directory
You can pass the storage path, or selectDirectory.DEFAULT_DIR
to keep the default path.
.directory(ImagePicker.Directory.DEFAULT)
//OR
.directory(Environment.getExternalStorageDirectory()+"/myFolder")
scale
You can scale the image to a a minimum width and height. This will only be used if compressLevel is set. To avoid OutOfMemory issues, ensure this is used.
.scale(500, 500)
allowMultipleImages
Extra used to select and return multiple images from gallery CANNOT select single image from gallery if this feature was enabled
.allowMultipleImages(true)
enableDebuggingMode
used to print Image Picker Log
.enableDebuggingMode(true)
It's an extenstion that allow you to return an observable from ImagePickerBuilder, all you need is to add below dependency and then return the observable from ImagePickerHelper
class.
Gradle
dependencies {
compile 'net.alhazmy13.MediaPicker:rxjava:(Last_version)'
}
new ImagePickerHelper(
new ImagePicker.Builder(Context)
...)
.getObservable()
.subscribe(new Subscriber<List<String>>() {
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted() called with: " + "");
}
@Override
public void onError(Throwable e) {
Log.d(TAG, "onError()");
}
@Override
public void onNext(List<String> imagePaths) {
Log.d(TAG, "onNext() ");
}
});
- Create an object from
VideoPicker
- Override
onActivityResult
to receive the path of video.
You will need to create a new instance of VideoPicker
. Once the instance are configured, you can call build()
.
new VideoPicker.Builder(this)
.build();
In order to receive the path of video, you will need to override onActivityResult
.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == VideoPicker.VIDEO_PICKER_REQUEST_CODE && resultCode == RESULT_OK) {
String mPath = data.getStringExtra(VideoPicker.EXTRA_VIDEO_PATH);
//Your Code
}
}
mode
to select the mode, you can chose one ot theseCAMERA
,GALLERY
orCAMERA_AND_GALLERY
.mode(VideoPicker.Mode.CAMERA)
extension
You can change the extanion of image to_MP4
,_MKV
or_3GP
.extension(VideoPicker.Extension._MP4)
directory
You can pass the storage path, or selectDirectory.DEFAULT_DIR
to keep the default path.
.directory(VideoPicker.Directory.DEFAULT)
//OR
.directory(Environment.getExternalStorageDirectory()+"/myFolder")
You can change the strings be overwriting below resources in your project.
<string name="media_picker_select_from">Select From:</string>
<string name="media_picker_camera">Camera</string>
<string name="media_picker_gallery">Gallery</string>
<string name="media_picker_ok">Ok</string>
<string name="media_picker_cancel">Cancel</string>
<string name="media_picker_some_permission_is_denied">Some Permission is Denied</string>
<string name="media_picker_you_need_to_grant_access_to">You need to grant access to</string>
<string name="media_picker_read_Write_external_storage"><![CDATA[Read & Write External Storage]]></string>
The MIT License (MIT)
Copyright (c) 2015 Abdullah Alhazmy
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.