Image gallery library by using coroutine to help user to choose image (single or multi) from android device without usage of android gallery implicit intent. This library supports AndroidX and it is very recommended to use AndroidX in your project.
- This library has already been included in jitpack.io. In order to use it, you should add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation 'com.github.WendyYanto:android-image-picker:v1.3.0'
}
- Register the code below in Android.Manifest.xml
// Provide permission to read image in android device
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application>
// Register Activity
<activity android:name="dev.wendyyanto.imagepicker.features.gallery.view.GalleryActivity" />
</application>
- Implement dependency injection of this plugin by initialize this code once. Usage of MediaDao is to fetch images using coroutines. It is recommended to add this code when in the UI that require
GalleryActivity
// Kotlin
override fun onCreate() {
super.onCreate()
Injector.store(MediaDao::class.java, MediaDao(this))
}
// Java
@Override
public void onCreate() {
Injector.INSTANCE.store(MediaDao.class, new MediaDao(this));
}
Definition of Intent Extra's for GalleryActivity :
MAX_COUNT
: Maximum images user can select from gallery (default value: 1)SUBMIT_BUTTON_STYLE
: Style attributes for submit button (default: android button style)THEME
: Theme for GalleryActivity (default: your app theme)CATEGORY_DROPDOWN_ITEM_LAYOUT
: Layout for your image category spinner item at the toolbar (default:android.R.layout.simple_spinner_dropdown_item
)
Example:
val intent = Intent(this@MainActivity, GalleryActivity::class.java)
intent.putExtra(GalleryActivity.MAX_COUNT, 10)
intent.putExtra(GalleryActivity.SUBMIT_BUTTON_STYLE, R.style.MyButton)
intent.putExtra(GalleryActivity.THEME, R.style.GalleryTheme)
intent.putExtra(GalleryActivity.CATEGORY_DROPDOWN_ITEM_LAYOUT, R.layout.spinner_item)
Example Output: