Easy to use Image Picker library
- minSdkVersion 10
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.samkazmi:SimpleImageSelect:1.0'
}
Initalize some variables in your onCreate
method
SimpleImageSelect.Config(this, "Choose Profile Picture from", "FolderName");
FolderName
is the name of the folder where your selected image will be saved
it uses ExternalStorage for now to save files.
SimpleImageSelect.chooseSingleImage(Config.TYPE_CHOOSER_BOTH, this);
SimpleImageSelect.chooseSingleImage(Config.TYPE_CAMERA, this);
SimpleImageSelect.chooseSingleImage(Config.TYPE_CHOOSER_GALLERY_ONLY, this);
Note: If you are using this method in a fragment you must use this
as the second param
try {
String path = SimpleImageSelect.onActivityResult(this, requestCode, resultCode, data);
if (path != null) {
Log.v("MainActiviy", "app: " + path);
}
} catch (IOException e) {
e.printStackTrace();
} try {
String path = SimpleImageSelect.onActivityResult(this, requestCode, resultCode, data);
if (path != null) {
Log.v("MainActiviy", "app: " + path);
}
} catch (IOException e) {
e.printStackTrace();
}
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
SimpleImageSelect.ClearConfig(this);