Yalantis / uCrop

Image Cropping Library for Android
https://yalantis.com/blog/introducing-ucrop-our-own-image-cropping-library-for-android/
11.86k stars 2.16k forks source link

File Provider in lightWeight Version #334

Closed bloomer20102011 closed 7 years ago

bloomer20102011 commented 7 years ago

Do you want to request a feature or report a bug? feature

app closes in light weight version but doesnt close in native version becasue of FIle Provider

severianremi commented 7 years ago

Hello, @bloomer20102011. Could you give more information about this issue? Is this issue reproduce for all android versions or only for pre-lollipop? Did you give Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION? Please, describe: Where. What happened. Conditions. Steps to reproduce: What should I do to reproduce the issue. Thanks!

bloomer20102011 commented 7 years ago

it doesnt close anymore but doesnt read the image and yes i gave the gallery pick intent Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION

where it happend : it happens when i give the ucrop activity of the image provided by gallery

what happend : it gives black screen then activity closes when image is picked from gallery then url is directly given to ucrop activity by : intent.getdata();

it only woks in two conditions

  1. the app has storage permissions given by the user 2.the image from gallery is first stored in the app directory which is weird which i implemented as a workaround

but in native version it works normal

severianremi commented 7 years ago

Could you provide your code to understand what went wrong? Is it actual for all devices? Today I try to reproduce your situation and can't reproduce such behavior

bloomer20102011 commented 7 years ago

//PICK IMAGE FROM GALLERY

Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); activity.startActivityForResult(Intent.createChooser(intent, activity.getString(R.string.select_image)), number);

Handle on activity result if (resultCode == RESULT_OK && requestCode == 150) { UCrop.of(data.getData(), Uri.fromFile(new File(getFilesDir(), AppController.tempo.FileToPut.name()))) .withMaxResultSize(1500, 1500) .withOptions(AppController.getInstance().getUcropOptions(EditActivity.this,R.string.edit_image_face)) .start(EditActivity.this); }
**then gives black screen and closes

it only works if the user has given the app storage perrmission although the uri it self is readable and doesnt require storage permission or the the work around i do is save the image first in app directory and get the url through FileProvider

same code but with the other version and it works

UCROP VERSION : compile 'com.github.yalantis:ucrop:2.2.1' Mobile : sony z3 Dual api 23

severianremi commented 7 years ago

Related to Android 6.0 permissions. Grant storage permissions to the user and everything is fine. Just do as in our example:

private void pickFromGallery() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermission(Manifest.permission.READ_EXTERNAL_STORAGE, getString(R.string.permission_read_storage_rationale), REQUEST_STORAGE_READ_ACCESS_PERMISSION); } else { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(Intent.createChooser(intent, getString(R.string.label_select_picture)), REQUEST_SELECT_PICTURE); } }

@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case REQUEST_STORAGE_READ_ACCESS_PERMISSION: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { pickFromGallery(); } break; default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); } }

It work for all cases.