igreenwood / SimpleCropView

A simple image cropping library for Android.
MIT License
2.48k stars 465 forks source link

Content provider in cache directory #135

Open strangegt opened 6 years ago

strangegt commented 6 years ago

I dont save crop image in external storage, i use file provider in chache dir

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path name="cache" path="." />
</paths>

the code for crop mCropView.startCrop(createSaveUri(), mCropCallback, mSaveCallback);

public Uri createSaveUri() {
    mCropView.setCompressFormat(Bitmap.CompressFormat.PNG);
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "PNG_" + timeStamp + "_.png";

    return getFileProviderUri(new File(getActivity().getCacheDir(), imageFileName));
}

private Uri getFileProviderUri(File photoFile) {
    Uri photoURI;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        photoURI = FileProvider.getUriForFile(getActivity(),
                "com.strangegt.crop.fileprovider",
                photoFile);
    } else {
        photoURI = Uri.fromFile(new File(photoFile.getAbsolutePath()));
    }
    return photoURI;
}

This code works on 1.1.4,, i get the grop image in the content uri, and can use it but in 1.1.7 stop working, the file is saved but this call fail, in saveImage method, and dont get success crop Utils.updateGalleryInfo(getContext(), uri); I think fail because i dont save in external storage