Skip to content

Latest commit

 

History

History
96 lines (76 loc) · 3.91 KB

README.md

File metadata and controls

96 lines (76 loc) · 3.91 KB

Image Picker+

Simple Photo Picker for Android. Supports jpeg, png, webp formats. Works on Android version 5 or higher.

Some functions:

✔️ Pick a picture from the gallery without storage permission.
✔️ Take a photo from the camera (camera permission is optional).
✔️ Rotate or crop the captured image.
✔️ Save the final image to the app's local directory so you can use it like a File, without a ContentResolver.
✔️ Transform result to Jpeg / PNG / WebP automatically if needed.

Why one more photo picker?

  1. Photopicker from Google is not good enough.
  2. Single entry point for camera/gallery images.
  3. Other libraries that I've tried have bugs and/or abandoned.

This library:

  1. Doesn't require Android 11 or Google Play services as the photopicker from Google does.
  2. Covers both gallery and camera sources of image.
  3. Has basic image editor (rotate / crop)

Why this library doesn't require storage permissions?

It doesn't have access to the file system of the device. The system component provides content to this lib instead.
See Intent.ACTION_OPEN_DOCUMENT for more details.

Why camera permission is optional?

It's vaguely mentioned in the documentation. Unless you declare the camera permission in your app's manifest, you don't need to ask for runtime permission for this library. If you declare the camera permission (for other features in your app), this lib will ask for runtime permission automatically.

How rotation / crop works?

Thanks to uCrop library

Usage

For example in your activity:

// You can use the modern way to receive the result like this. Or you can use onActivityResult().
private val launcher = registerForActivityResult(StartActivityForResult()) {
    it?.data?.data?.let { uri ->
        // Done. Use the received uri with captured image inside.
        imageView.setImageURI(uri)
    }
}

ImagePickerPlus
    .createIntent(
        activity = this,
        PickRequest(
            source = PickSource.GALLERY, // or PickSource.CAMERA
            transformation = ImageTransformation(
                maxSidePx = 1024, // Or -1 if limit isn't needed
                encodeToFormat = ImageFormat.JPEG, // Or null if transformation isn't needed
            ),
        )
    )
    .let { launcher.launch(it) }

Sample application:

picture

Setup:

  1. Add maven { url 'https://jitpack.io' } to the allprojects or dependencyResolutionManagement section in top-level build.gradle or settings.gradle.
    For example (settings.gradle):
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}
  1. Add implementation 'com.github.Andrew0000:ImagePickerPlus:$latest_version' to the module-level build.gradle

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.