It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.

Overview

Release Awesome

Shutter-Android

It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.

What is Shutter?

Shutter is an Android library to take photos, record videos, pick images/videos from gallery, with ease. I always have difficulty working with images/videos while developing Android apps especially since file providers were added.

Why use Shutter?

  • Less bugs. No more publishing apps and have your app crash on a user's devices because of file permission issues you did not handle or boilerplate code you forgot to include (believe me, I have done this many times).
  • No more copy/paste of boilerplate code. Install lib, call Shutter, and be done across all of your apps.
  • Lightweight. Check out the methods count here
  • No Android runtime permissions needed. No need to ask for reading/writing files permissions.
  • Java and Kotlin support. Shutter-Android is written in Kotlin :)

Install

Install Shutter-Android via JitPack.io.

Add the following to the root build.gradle file (/build.gradle) at the end of repositories:

allprojects {
	repositories {
	    ...
		maven { url 'https://jitpack.io' }
	}
}

Then, add the following to your project build.gradle file (app/build.gradle)

dependencies {
    compile 'com.github.levibostian:Shutter-Android:0.2.2'
}

(the latest release to date is version: Release)

Take images easily with Shutter

When you want to take a photo in your Activity or Fragment, call Shutter:

shutterResultListener = Shutter.with(this)
    .takePhoto()
    .usePrivateAppInternalStorage()
    .snap(object : Shutter.ShutterResultCallback {
        override fun onComplete(result: Shutter.ShutterResult) {
            result.absoluteImageFile // <--- file:// path to the image.
        }
        override fun onError(humanReadableErrorMessage: String, error: Throwable) {
            Log.d("SHUTTER_EXAMPLE_APP", "Error encountered: ${error.message}")
            Snackbar.make(findViewById(android.R.id.content), humanReadableErrorMessage, Snackbar.LENGTH_LONG).show()
        }
})

If you want to record a video, use: Shutter.with(this).recordVideo(). Pick image from the device gallery, use: Shutter.with(this).getPhotoFromGallery(). Pick video from the device gallery, use: Shutter.with(this).getVideoFromGallery().

When you call .snap() to tell Shutter to take a photo, save the result object. You will need to call if on your Activity or Fragment's onActivityResult() call:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    if (!shutterResultListener!!.onActivityResult(requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data)
    }
}

Shutter-Android uses the FileProvider API to take photos. Because of this, Android requires you to add the following to your manifest file:

<application
   ...>
    <provider android:name="android.support.v4.content.FileProvider"
              android:authorities="${applicationId}.fileprovider"
              android:exported="false"
              android:grantUriPermissions="true">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
                   android:resource="@xml/file_paths" />
    </provider>
</application>

Then, create a file: app/src/main/res/xml/file_paths.xml to specify permissions of the FileProvider API. For now, this is what the file contents should look like:

<?xml version="1.0" encoding="utf-8"?>
<paths>
</paths>

Inside of this file, add some entries depending on your situation.

  • If you are capturing an image using .usePrivateAppInternalStorage() add the following line between :
<files-path name="internal_pictures_files" path="Pictures/" />
  • If you are capturing an image using .usePrivateAppExternalStorage() add the following line between :
<external-files-path name="external_pictures_files" path="Pictures/" />
  • If you are recording a video using .usePrivateAppInternalStorage() add the following line between :
<files-path name="internal_videos_files" path="Movies/" />
  • If you are recording a video using .usePrivateAppExternalStorage() add the following line between :
<external-files-path name="external_videos_files" path="Movies/" />

Here is an example file_paths.xml file:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <files-path name="internal_pictures_files" path="Pictures/" />
    <external-files-path name="external_videos_files" path="Movies/" />
</paths>

More info about how to specify permissions can be found in the official docs

Done!

Author

Levi Bostian image

Notes/Warnings:

  • The Shutter API might confuse you because you are able to save your captured media to "private internal or external storage" with the option to also "save the captured media to the gallery". This is true but not true. desi TL;DR Your photos/videos captured with Shutter may be added to the public gallery on the Android device no matter how you setup Shutter.

Android is a fragmented operating system as we all know. Even if you decide to save your photos to private internal storage and not save to the gallery, your photo still might be saved to the gallery. Shutter has no control over this. Every user device will behave differently depending on the camera app that is installed. Shutter takes photos by using an Android Intent which asks a camera app on the user's device to take the photo for us. That camera app has the ability to do with your photo whatever it wishes after it is taken including but not limited to saving the photo to the public gallery.

The only way to enforce your photos are private to your app and your app only is to add the camera functionality to your own app which we will not be covering in Shutter at this time and probably never.

"Why does shutter even give the ability to add the captured media to the public gallery if it might do it already?" you answered your own question there. Might is the keyword. Adding the ability to add the media to the gallery through Shutter is to assert it is added to the gallery even if the camera app decides not to when the photo/video is captured.

  • Create a loading UI while working with Shutter if you decide to show a photo/video after capturing it.

Shutter does labor intensive tasks in a background thread. What this means is that your app will go back into focus right away after the device camera or gallery apps are launched but the photo/video may not be ready for you yet. Shutter will call the callback you give to .snap() when the photo/video is ready. When your app goes back into focus, I would make sure to have some sort of loading UI telling the user that you are loading the photo/video and it will be available shortly. Once the callback you send to .snap() is called with the file path or an error, then you can change your UI to show the video/image and hide the loading UI.

Contribute

Shutter is open for pull requests. Please, read the STYLE.md doc in the root of this project which will answer some questions for you as to why Shutter is built the way it is.

Credits

Comments
  • Failed to find configured root

    Failed to find configured root

    I am trying to use a different line than the default <files-path name="internal_pictures_files" path="Pictures/" />

    to something like

    <files-path name="internal_pictures_files" path="images/" />

    and it causes app crash and subsequent relaunch. How should I really use to save to different directory.

    FYI: I am a novice.

    opened by gnanakeethan 5
  • When I implement Shutter-Android

    When I implement Shutter-Android

    When I implement Shutter-Android. Before even I start consuming I get this: Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors

    opened by ajkerfaisal 1
  • Add Android awesome badge to README.

    Add Android awesome badge to README.

    [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
    

    Here is the link to where you can find the lib.

    opened by levibostian 1
  • Deprecate library for Android 11+?

    Deprecate library for Android 11+?

    opened by levibostian 0
  • Have common builder

    Have common builder

    Here is a code sample of what I am trying to do:

    var shutterBuilder = Shutter.with(this)
    
    if (useCamera) shutterBuilder = shutterBuilder.takePhoto().usePrivateAppExternalStorage()
    else shutterBuilder = shutterBuilder.getPhotoFromGallery()
    
    shutterResult = shutterBuilder
    .snap(object : ShutterResultCallback {
    

    I am trying to dynamically choose what builder I use. Depending on boolean variable useCamera.

    Problem is I cannot do this because the builder objects being returned from each are not common.

    What I could do:

    1. add a function build() that builds to a common object that you can then call snap() on.
    2. Will a kotlin DSL allow me to solve this problem from a different angle?
    opened by levibostian 0
  • Android Q scoped storage

    Android Q scoped storage

    Android Q beta has added scoped storage.

    It affects apps that store files to storage. You can store private files without needing extra permissions or you can use the devices media collections.

    https://developer.android.com/preview/privacy/scoped-storage

    opened by levibostian 1
  • Add to docs how to configure app for auto backup

    Add to docs how to configure app for auto backup

    I was reading the docs for auto backup recently and it talks about how docs in getExternalStorage() are automatically backed up.

    Add to docs how to exclude photos taken by Shutter.

    opened by levibostian 1
  • Add ability to specify the directory that photos/videos are stored after being taken.

    Add ability to specify the directory that photos/videos are stored after being taken.

    See issue https://github.com/levibostian/Shutter-Android/issues/8#issuecomment-376740206 for the discussion behind this feature.

    In the builder to take a photo or record a video, add the ability to specify the name of a directory for the photos/videos.

    Should be pretty easy. Here is the code where the directory is hard coded currently. Here is where we give the user the ability to specify the filename so we can use that same idea to give the user the ability to specify a directory.

    Tasklist:

    • [ ] Give user ability to specify the directory for taking a photo and recording a video.
    • [ ] Update readme docs showing that you can now specify a directory to save photos/videos. Also, update the readme docs about the manifest permissions where you can use "Pictures" by default, but you can also specify more for custom directories.
    opened by levibostian 0
  • Null pointer exceptions in Builders

    Null pointer exceptions in Builders

    I have been using the lib in a couple apps of mine and I have run into NPEs.

    In the builder patterns where I am doing companion.getActivity()!!, for example, could have a null activity.

    opened by levibostian 2
Releases(0.2.2)
  • 0.2.2(Jul 26, 2017)

    • Use asynctasks for running in background and UI threads for getting images/videos from gallery.
    • Fix crash where I would not return from function if user cancelled camera/gallery intent.
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Jul 26, 2017)

    • Allow user to get photo/video from gallery.
    • Update example app to demonstrate the ability to get photos and videos from gallery.
    • Update README to reflect the ability to get photos/videos from gallery and prepare for a more formal release.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Jul 25, 2017)

    First release for Shutter-Android library.

    • Create Shutter library to be able to capture photos from camera.
    • Optionally, declare filename, where you would like to save photos to.
    • Create example app.
    • README chats about how to use library.
    Source code(tar.gz)
    Source code(zip)
Owner
Levi Bostian
Android, iOS, node API developer. Senior dev @customerio. Hacker @curiosityio . Environmental activist, minimalist, organic gardener. they/he
Levi Bostian
Easy Android camera integration, advanced features.

CameraViewEx This is an extended version of Google's cameraview library with better stability and many more features. CameraViewEx highly simplifies i

Priyank Vasa 205 Dec 24, 2022
[Android Library] Get easy access to device information super fast, real quick

DeviceInfo-Sample Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the d

Anitaa Murthy 193 Nov 20, 2022
A mobile application developed for *Android* devices, aimed at 11th grade students in which they can take some basic training tests for presentation of external tests.

ApliKTest11 Application with Kit of questions and Knowledge Test for the preparation of the Saber Test. Description A mobile application developed for

Mike Molina 0 Dec 13, 2021
Muhammad Ariananda 7 Jul 17, 2022
A Gallery app developed using kotlin and MVVM architecture with Coroutine

A Gallery app developed using kotlin and MVVM architecture Loading image from un

Atiar Talukdar 1 Dec 21, 2021
Firebase with MVVM is a series of videos in which you will learn how to implement firebase with MVVM along with UI designs, GitHub branches, merging, and resolving conflicts.

In this project we will learn about Firebase Implementation with MVVM Architecture. It is a basic level Course and will go with project based approach so can understand better that how the things are working.

Shahzad Afridi 29 Jan 1, 2023
Blog implemented via the Storyblok Kotlin Multiplatform SDK (Android, JVM)

storyblok-mp-SDK-blog ... a showcase of using the Storyblok Kotlin Multiplatform Client to build a blog application (Android, JVM) What's included ??

Mike Penz 5 Sep 28, 2022
BlurHash support for iOS, Android and JVM via Kotlin Multiplatform

blurhash A Kotlin Multiplatform library to use blurhash in your Android App, iOS / Mac App & JVM Backend. Android iOS JVM Why? If you've tried using b

Niklas Baudy 19 Nov 17, 2022
A Kotlin library for interacting with Discord via IPC

KDiscordIPC A Kotlin library for interacting with Discord via IPC Features Fully documented codebase macOS and Linux support (including M1 Macs, Windo

Conor Byrne 17 Dec 14, 2022
A pair of applications provide a direct means of integrating with one another via application programming interfaces (APIs)

What is a native integration? It's when a pair of applications provide a direct means of integrating with one another via application programming interfaces (APIs). Once integrated, data can flow between the apps and become more readily available to your employees.

Behruz Hurramov 2 Jan 17, 2022
🛠️ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files.

DrawableToolbox English | 中文 The missing DrawableToolbox for Android. Create drawables programmatically and get rid of the boring and always repeated

Hong Duan 1.1k Jan 4, 2023
With Viola android face detection library, you can detect faces in a bitmap, crop faces using predefined algorithm and get additional information from the detected faces.

Viola Viola android face detection library detects faces automatically from a bitmap, crop faces using the predefined algorithms, and provides supplem

Darwin Francis 58 Nov 1, 2022
KaMP Kit by Touchlab is a collection of code and tools designed to get your mobile team started quickly with Kotlin Multiplatform.

KaMP Kit Welcome to the KaMP Kit! About Goal The goal of the KaMP Kit is to facilitate your evaluation of Kotlin Multiplatform (aka KMP). It is a coll

Touchlab 1.7k Jan 3, 2023
Example mod with Mixin to help you to get started with creating a mod with mixins.

ExampleMixinMod Example mod with Mixin to help you to get started with creating a mod with mixins. For usage of mixins, see here. Also, remember to tu

null 0 Dec 16, 2021
Aarón Calixto Andrade 0 Dec 27, 2021
A set of highly-opinionated, batteries-included gradle plugins to get you started building delicious multi-module Kotlin projects

Sourdough Gradle What is Sourdough Gradle? Sourdough is a set of highly opinionated gradle plugins that aim to act as the starter for your Kotlin proj

Backbone 0 Oct 3, 2022
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

Vehement 8 Nov 26, 2022
A flutter plugin to scan stripe readers and connect to the them and get the payment methods.

stripe_terminal A flutter plugin to scan stripe readers and connect to the them and get the payment methods. Installation Android No Configuration nee

Aawaz Gyawali 8 Dec 29, 2022
A nice weather that helps you get all information including: current weather, hourly weather and also forecasts for 16 days

WeatherForecast This is an ongoing project where I fetch all the weather data using Retrofit and Kotlin Coroutines over two APIs containing both curre

null 2 Jul 26, 2022