ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - levibostian/Shutter-Android: It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.
It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.  - GitHub - levibostian/Shutter-Android: It's finally easy to take photos/videos via camera ...
Visit Site

GitHub - levibostian/Shutter-Android: It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.

GitHub - levibostian/Shutter-Android: It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.

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

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory