Git Product home page Git Product logo

smartimagepicker's Introduction

Simplified abstraction over Android Image Cropper library to pick images from gallery or camera and crop them if needed.

Note

This library is currently unsupported because I've switched my focus to Flutter and don't plan fixing any bugs any time soon

Usage

Add this line to build.gradle

compile 'com.myhexaville:smart-image-picker:1.0.4'

Create new instance and save it as field

imagePicker = new ImagePicker(this, /* activity non null*/
                null, /* fragment nullable*/
                imageUri -> {/*on image picked */
                    imageView.setImageURI(imageUri);
                })
                .setWithImageCrop(
                        1 /*aspect ratio x*/
                        1 /*aspect ratio y*/);

If calling from Activity

Override Activity's methods to delegate permissions to ImagePicker and resulting image

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    imagePicker.handleActivityResult(resultCode,requestCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    imagePicker.handlePermission(requestCode, grantResults);
}

Open Picker

There's two methods available

imagePicker.openCamera();
imagePicker.choosePicture(true /*show camera intents*/);

First one opens camera directly, second shows an intent picker, where user picks from desired application. You can include/exclude camera intents with boolean.

That's it, if you don't need to crop image, don't call setWithImageCrop() in the chain. By default it's disabled. And if you want to get a file after you picked image, you can get it with this method

File file = imagePicker.getImageFile();

If calling from Fragment

Create instance

imagePicker = new ImagePicker(getActivity(),
                this,
                imageUri -> {/*on image picked */
                    imageView.setImageURI(imageUri);
                })
                .setWithImageCrop(
                        1 /*aspect ratio x*/
                        1 /*aspect ratio y*/);

Overriden methods should be in your Fragment

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    imagePicker.handleActivityResult(resultCode, requestCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    imagePicker.handlePermission(requestCode, grantResults);
}

But your fragment won't get activity result callback itself. You need to call it manually. Add this code to activity that hosts your fragment

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    List<Fragment> fragments = getSupportFragmentManager().getFragments();
    if (fragments != null) {
        for (Fragment f : fragments) {
            if (f instanceof YourFragment) {
                f.onActivityResult(requestCode, resultCode, data);
            }
        }
    }
}

You can get a sample app here

You don't need to add any permissions to manifest, everything is merged automatically from library's manifest file

smartimagepicker's People

Contributors

ihorklimov avatar miwaniec avatar shankar75031 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

smartimagepicker's Issues

Image can't be uploaded into a texture

Error recieved on a HTC one X running 4.2.2 not sure on the resolution of the display, is this something we can handle or something you'd need to work on, let me know and I can provide logs where needed

No confrim button in crop

When select the image and open crop the image, doesnt exists a button or something to done and return the image,

Could not resolve com.android.support:appcompat-v7:27.+.

just started getting an exception today :

Error:FAILURE: Build failed with an exception.

  • What went wrong:
    Could not resolve all files for configuration ':app:releaseCompileClasspath'.

Could not resolve com.android.support:appcompat-v7:27.+.
Required by:
project :app > com.myhexaville:smart-image-picker:1.0.4 > com.theartofdev.edmodo:android-image-cropper:2.6.0
Could not resolve com.android.support:appcompat-v7:27.0.1.
> Could not get resource 'https://jcenter.bintray.com/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar'.
> Could not HEAD 'https://jcenter.bintray.com/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar'.
> Read timed out

Licence

@IhorKlimov I would like to use your library in my application but there is no licence. Could you add a licence to this repo? Thank you.

Window Overlapping

When i am using image picker in multiple fragment windows get overlap multiple times

getImageFile returns null when crop is disabled

I don't know if it's by design and you forgot to mention it, but when calling (Kotlin code) :

imagePicker = ImagePicker(this, null, { uri -> imagePicker.getImageFile() // null } ) imagePicker?.choosePicture(true)

getImageFile() returns null. In fact in your code you only set imageFile when used with the crop activity.
Nowhere you mention this fact, you simply say that to get the file, we should call getImageFile()

Camera destination folder

How can I change camera destination folder?
I found a function in your code
private Intent getCameraIntent()
And there is generation of the file
Can you make an option to set custom destination path (and I suppose with custom fileprovider authority)?

Crash on start

when I call imagePicker.choosePicture(true); I have this error:

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/*********/files/images/outputImage1529499833245.jpg
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:738)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)
at com.myhexaville.smartimagepicker.ImagePicker.getCameraIntent(ImagePicker.java:259)
at com.myhexaville.smartimagepicker.ImagePicker.startImagePickerActivity(ImagePicker.java:288)
at com.myhexaville.smartimagepicker.ImagePicker.choosePicture(ImagePicker.java:85)

READ Permissions and also no way to proceed from Crop?

When trying to select image, Android first asks for permissions (write?) and I accept. But then I can not select an image:

11-13 14:24:16.265 4183-5697/? E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/file from pid=4092, uid=10050 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:608)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:483)
at android.content.ContentProvider$Transport.query(ContentProvider.java:212)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
at android.os.Binder.execTransact(Binder.java:565)

Also - using the crop built in, shows the image and crop but there is no way to proceed/save once resized in the cropper?

Blank files getting created in our apps cache directory

Every time we select an image after cropping it, a file with it's name like 'cropped12345.jpg' gets created in the internal cache directory of our app. The same file is visible in the gallery. Is there any way to delete the file from cache folder or hide them.?
Or should the ImagePicker create the same file in Context.MODE_PRIVATE.?

Crash take picture Samsung Camera (Android 16)

java.lang.SecurityException: Permission Denial: opening provider com.myhexaville.smartimagepicker.CustomFileProvider from ProcessRecord{436b0a00 15507:com.sec.android.app.camera/u0a76} (pid=15507, uid=10076) that is not exported from uid 10134

NullPointerException - Samsung Galaxy S4 - Android 5.0.1

05-27 14:45:15.592 6787-6787/com.myhexaville.androidimagepicker E/AndroidRuntime: FATAL EXCEPTION: main Process: com.myhexaville.androidimagepicker, PID: 6787 java.lang.RuntimeException: Unable to resume activity {com.myhexaville.androidimagepicker/com.myhexaville.androidimagepicker.activity_example.ActivityExample}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=null} to activity {com.myhexaville.androidimagepicker/com.myhexaville.androidimagepicker.activity_example.ActivityExample}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.myhexaville.smartimagepicker.ImagePicker.handleActivityResult(int, int, android.content.Intent)' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3394) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3425) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2763) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4462) at android.app.ActivityThread.access$1000(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1454) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5942) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=null} to activity {com.myhexaville.androidimagepicker/com.myhexaville.androidimagepicker.activity_example.ActivityExample}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.myhexaville.smartimagepicker.ImagePicker.handleActivityResult(int, int, android.content.Intent)' on a null object reference at android.app.ActivityThread.deliverResults(ActivityThread.java:4058) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3380) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3425)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2763)  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4462)  at android.app.ActivityThread.access$1000(ActivityThread.java:177)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1454)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:145)  at android.app.ActivityThread.main(ActivityThread.java:5942)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.myhexaville.smartimagepicker.ImagePicker.handleActivityResult(int, int, android.content.Intent)' on a null object reference at com.myhexaville.androidimagepicker.activity_example.ActivityExample.onActivityResult(ActivityExample.java:31) at android.app.Activity.dispatchActivityResult(Activity.java:6549) at android.app.ActivityThread.deliverResults(ActivityThread.java:4054) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3380)  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3425)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2763)  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4462)  at android.app.ActivityThread.access$1000(ActivityThread.java:177)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1454)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:145)  at android.app.ActivityThread.main(ActivityThread.java:5942)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 

CropImageActivity issue

hi !

after picking an image from gallery or camera i got "java.lang.RuntimeException: Unable to start activity ComponentInfo{co.lyan.lyandroid/com.theartofdev.edmodo.cropper.CropImageActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class com.linchaolong.android.imagepicker.cropper.CropImageView " error message .
how can fix it ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.