Android library for getting photo or video from a device gallery, cloud or camera. Working with samsung devices. Made by Stfalcon

Overview

ContentManager

Library for getting photos, videos or files of any type from a device gallery, external storage, cloud(Google Drive, Dropbox and etc) or camera. With asynchronous load from the cloud and fixed bugs for some problem devices like Samsung or Sony.

Who we are

Need iOS and Android apps, MVP development or prototyping? Contact us via [email protected]. We develop software since 2009, and we're known experts in this field. Check out our portfolio and see more libraries from stfalcon-studio.

Download

Download via Gradle:

compile 'com.github.stfalcon:contentmanager:0.5'

or Maven:

<dependency>
  <groupId>com.github.stfalcon</groupId>
  <artifactId>contentmanager</artifactId>
  <version>0.5</version>
  <type>pom</type>
</dependency>

Migration to version 0.5

In version 0.5 we have removed callback onLoadContentProgress(int loadPercent)(because it is very hard to calculate loadPercent correctly) and replaced it with callback onStartContentLoading() to handle a start of loading content. So if you are using ContentManager previous version, you need to make some correction after updating ContentManager version to 0.5. Also, we have added new cool feature: picking files with any types.

Usage

Add the folowing permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Implement callback interface:

public class MainActivity extends AppCompatActivity implements ContentManager.PickContentListener {

Then implement PickContentListener methods:

/**
* Success result callback
*
* @param uri         Content uri
* @param contentType If you pick content can be Image or Video, if take - only Image
*/
@Override
public void onContentLoaded(Uri uri, String contentType) {
   if (contentType.equals(ContentManager.Content.IMAGE.toString())) {
       //You can use any library for display image Fresco, Picasso, ImageLoader
       //For sample:
       ImageLoader.getInstance().displayImage(uri.toString(), ivPicture);
   } else if (contentType.equals(ContentManager.Content.FILE.toString())) {
       //handle file result
       tvUri.setText(uri.toString());
   }
}
        
/**
* Call when loading started
*/
@Override
public void onStartContentLoading() {
  //Show loader or something like that
  progressBar.setVisibility(View.VISIBLE);
}

/**
* Call if have some problem with getting content
*
* @param error message
*/
@Override
public void onError(String error) {
  //Show error
}

/**
* Call if user manual cancel picking or taking content
*/
@Override
public void onCanceled() {
  //User canceled
}

Declare field:

private ContentManager contentManager;

Create instance where "this" is your activity:

contentManager = new ContentManager(this, this);

Override onActivityResult method of activity. It is needed for handling the result:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  contentManager.onActivityResult(requestCode, resultCode, data);
}

Override onRequestPermissionsResult method to handle realtime permissions:

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    contentManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

Override onSaveInstanceState, onRestoreInstanceState. It is needed for fixing bugs with some Samsung and Sony devices when taking photo in a landscape mode:

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);
  contentManager.onRestoreInstanceState(savedInstanceState);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
  super.onSaveInstanceState(outState);
  contentManager.onSaveInstanceState(outState);
}

Pick image:

contentManager.pickContent(ContentManager.Content.IMAGE);

Pick video:

contentManager.pickContent(ContentManager.Content.VIDEO);

Pick file:

contentManager.pickContent(ContentManager.Content.FILE);

Take photo from camera:

contentManager.takePhoto();

Take a look at the sample project for more information

Thanks

Thanks to @coomar2841 and his Android Multipicker Library. We peeked at him some points in the implementation of picking files.

License

Copyright 2017 stfalcon.com

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.
Comments
  • onActivityResult data is null

    onActivityResult data is null

    Hi, when using contentmanager.takephoto() on some devices the app crashes. I can see this error in logs:

    Exception java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=16, result=-1, data=null} to activity {...activity.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.content.Intent.getData()' on a null object reference

    It seems that on those devices, intent data received in onActivityResult is null.

    Devices on which I tested it and it works perfectly:

    • Samsung Galaxy S5 mini with android 5.1.1
    • LG Nexus 5 with android 6.0.1

    Devices on which I see this error:

    • Motorola Moto G with android 5.1
    • Huawei honor 6 with android 4.4.2
    • Android Studio official emulator
    opened by dotocan 5
  • onContentLoaded not called when don't keep activities is set and picking from gallery

    onContentLoaded not called when don't keep activities is set and picking from gallery

    Hello,

    thank you for your library. I found out that when I turn on the "don't keep activities" option the onContentLoaded is not called when picking an image from gallery. It works fine when taking a picture from cammera. Also when I don't have this option turned on it works for camera and gallery.

    I was using 0.1.1 version but after upgrade to 0.4.2 it is still the same. Do you have any idea where can by the problem?

    Fragments onActivityResult is called and it contains this code:

    @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); contentManager.onActivityResult(requestCode, resultCode, data); }

    Thank you for you response.

    opened by danielto 2
  • Previewing captured image?

    Previewing captured image?

    Hi,

    Picking image from gallery and putting it in ImageView works as it should. But how can I take a picture with camera and put that captured image into ImageView? I need to be able to take a picture with camera on one activity and then show that picture to the user few activities later.

    opened by dotocan 2
  • onLoadContentProgress(int loadPercent) called even for local images

    onLoadContentProgress(int loadPercent) called even for local images

    Hello,

    First, I want to thank you for your library. I'm asking a question about the onLoadContentProgress() call. I logged some information in this callback method and I can see that calls are done even for local images. I think this method should be called only for cloud images.

    Thanks, 16arm

    opened by 16arm 1
  • Not able to pick image from the gallery

    Not able to pick image from the gallery

    The library is not working, I tried picking up the image from the Gallery in Samsung S7 Edge but onActivityResult is never called.

    I am testing it inside the Fragment on Android OS version 6.0

    opened by Shajeel-Afzal 1
  • Method onError() called with error 'null', when i use the pickContent() to pick image or video !!!

    Method onError() called with error 'null', when i use the pickContent() to pick image or video !!!

    My device is redmi Note 4 running 7.0 I am calling the contentManager inside SupportFragment

    1. onActivityResult() returns the image data
    2. then onStartContentLoading called
    3. then onError with null parameter called and nothing gets loaded

    this library worked for first two days, now it is loading nothing

    opened by DilbagSandhu 0
  • The method contentManager.takePhoto() crashes the application, requiring the permission of android.permission.CAMERA

    The method contentManager.takePhoto() crashes the application, requiring the permission of android.permission.CAMERA

    The method contentManager.pickContent(ContentManager.Content.IMAGE) asks for permission when called, and the method contentManager.takePhoto() does not request permission and crashes the system. java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity clip={text/uri-list U:content://media/external/images/media/16349} (has extras) } from ProcessRecord{ea458e7 15188:com.kostasoft.help_signal_purchase/u0a207} (pid=15188, uid=10207) with revoked permission android.permission.CAMERA

    opened by kostasoft 0
  • Method onError() being called on Samsung Galaxy S7 device due to picture being taken on the past

    Method onError() being called on Samsung Galaxy S7 device due to picture being taken on the past

    Hi!

    I need to start saying thanks for the project, since it's being really helpful for implementing the functionality of taking photo and picking media from the gallery.

    About the issue I am having, it's related (at least until now) with the Samsung Galaxy S7 Device, which is not loading the picture after being taken (the picking from gallery works fine).

    It does call the method onError() with empty string from the interface ContentManager.PickContentListener. I have been debugging the internal code of the ContentManager class and have found this issue happens when verifying if the date of the picture is after the date that the camera intent has started (ContentManager.java, line 354). I notices this device is saving the picture as one day before the current day, so I am pretty sure this is the problem that is leading to this behaviour.

    Could you please provide one way to bypass this verification about the date of the picture being after the start date of the camera intent, or at least the fix (I don't know if it's Samsung software issue when saving the picture or the library is putting the date one day in the past)?

    Thanks one more time!

    opened by rodrigobressan 5
Owner
Stfalcon LLC
We are Stfalcon, mobile and web development company.
Stfalcon LLC
[NO LONGER MAINTAINED] Android library for better Picker DialogFragments

/!\ This Project is no longer maintained /!\ DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numb

Code-Troopers 2.7k Dec 29, 2022
An android library which provides a compact calendar view much like the one used in google calenders.

CompactCalendarView CompactCalendarView is a simple calendar view which provides scrolling between months. It's based on Java's Date and Calendar clas

SundeepK 1.5k Dec 9, 2022
FlipTimerView library for Android

FlipTimerView Preview FlipTimerView library for Android Getting started Add it in your root build.gradle at the end of repositories: allprojects { re

Anu S Pillai 314 Dec 28, 2022
[NO LONGER MAINTAINED] Android library for better Picker DialogFragments

/!\ This Project is no longer maintained /!\ DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numb

Code-Troopers 2.7k Dec 29, 2022
A customizable, easy-to-use, and functional circular time range picker library for Android

A customizable, easy-to-use, and functional circular time range picker library for Android. Use this library to mimic Apple's iOS or Samsung's bedtime picker.

Joery Droppers 251 Dec 30, 2022
Appleader707 1 Aug 9, 2022
Jetlime - A simple library for TimeLine view in Android

JetLime ⏱️ A simple yet highly customizable library for showing a TimeLine view

Pushpal Roy 107 Dec 6, 2022
Android Compose wheel picker library based on LazyColumn in vertical and LazyRow in horizontal.

About Android Compose wheel picker library based on LazyColumn in vertical and LazyRow in horizontal. Gradle Sample Default Item size Unfocused count

null 6 Dec 22, 2022
Nepali Date Picker library in Jetpack compose for android with Date conversion from BS to AD and vice-versa

Nepali Date picker Converter - Re in Compose This is a re-work of Nepali Date Picker Converter in jetpack compose and kotlin. English Locale Nepali Lo

Kiran Gyawali 4 Dec 23, 2022
Alwan 🎨 is an Android Jetpack Compose color picker library.

Alwan Alwan is an Android Jetpack Compose color picker library. Preview Recording.mp4 Download Gradle: dependencies { implementation 'com.raedapps:a

Raed Mughaus 6 Sep 16, 2022
JetCalendarView - A calendar library for Jetpack Compose

JetCalendar WIP 2022 Hit Refresh! Calendar view ❤️ Jetpack Compose License Copyr

Anmol Verma 8 Aug 17, 2022
A Material design back port of Android's CalendarView

Material Calendar View A Material design back port of Android's CalendarView. The goal is to have a Material look and feel, rather than 100% parity wi

Prolific Interactive 5.8k Jan 5, 2023
Standalone Android widget for picking a single date from a calendar view.

TimesSquare for Android Standalone Android widget for picking a single date from a calendar view. Usage Include CalendarPickerView in your layout XML.

Square 4.4k Dec 20, 2022
Pick a date or time on Android in style

Material DateTime Picker - Select a time/date in style Material DateTime Picker tries to offer you the date and time pickers as shown in the Material

null 4.7k Jan 4, 2023
A better calendar for Android

Caldroid Caldroid is a fragment that display calendar with dates in a month. Caldroid can be used as embedded fragment, or as dialog fragment. User ca

Roomorama 1.4k Jan 5, 2023
Wheel-like spinner widget for Android

Update Dec 2016 Library is discontinued There's still a lot of wheel libraries out there. Update Oct 2014 I am thinking of rewriting this control. Upd

Dimitri Fedorov 641 Jan 2, 2023
Android calendar view (like card)

android-calendar-card (Google Play Demo) Android calendar view (like card) Simple and easy to modify Author: Michał Szwarc #CalendarCardPager License

Michał Szwarc 473 Nov 10, 2022
An calender widget for your Android home screen.

Todo Agenda - Calendar and Task widgets for Android Todo Agenda is home screen widgets for your Android device. Each widget has its own settings and d

null 368 Dec 21, 2022
Android time range picker

TimeRangePicker TimeRangePicker is a library which can be used to select a time range. WARNING Requires android-support-v4 Description This library pr

Titto Jose 422 Nov 10, 2022