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.kitttn:async-media-loader-android:0.9.3'
}
dependencies {
implementation("com.github.kitttn:async-media-loader-android:0.9.3")
}
<dependency>
<groupId>com.github.kitttn</groupId>
<artifactId>async-media-loader-android</artifactId>
<version>0.9.3</version>
</dependency>
libraryDependencies += "com.github.kitttn" % "async-media-loader-android" % "0.9.3"
:dependencies [[com.github.kitttn/async-media-loader-android "0.9.3"]]
This simple yet powerful fragment allows you to convert selected or captured photos to Java File
object to send it later to your server, or to get Bitmap
for showing them in your <ImageView>
s.
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.kitttn:async-media-loader-android:0.9.3'
}
Sure. Just import it in your Activity / Fragment (via childFragmentManager
) etc. :
private val mediaFragment = MediaChooserFragment.newInstance()
Also don't forget to attach it:
supportFragmentManager.beginTransaction()
.add(mediaFragment, "ANY TAG YOU WISH")
.commit()
Then all you need is to call openCamera()
or openGallery()
on mediaFragment
instance:
cameraPhotoBtn.setOnClickListener { mediaFragment.openCamera() }
That's it!
This fragment will automatically handle permissions request and photo processing. All data processed will be delivered via Handler
s you defined while creating instance of MediaChooserFragment:
val mediaFragment = MediaChooserFragment.newInstance(fileHandler = { /* for File objects */ }, bitmapHandler = { /* for BitmapObjects */ }, errorHandler = { /*for all errors */ })
This fragment is written in Kotlin and uses coroutines to make it hard job off the main thread.
Pull requests are welcome!
A bit difficult to use it from Java.
Yes. newInstance()
definitely needs @JvmOverloads
annotation for ability to add only required methods from Java.
Solution: use Kotlin or Submit PR :)
Handling permissions requests is limited and responses are not supported.
Yes, you are right. The main idea was to keep this library as a quick option to request files.
Solution: Submit PR :)
Thanks for looking. Give it a try :)