Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startCrop throw "UnKown URI" #121

Closed
JanesenGit opened this issue Nov 5, 2017 · 8 comments
Closed

startCrop throw "UnKown URI" #121

JanesenGit opened this issue Nov 5, 2017 · 8 comments

Comments

@JanesenGit
Copy link

private Uri saveImage(Bitmap bitmap, final Uri uri) throws IOException, IllegalStateException {
mSaveUri = uri;
if (mSaveUri == null) {
throw new IllegalStateException("Save uri must not be null.");
}

OutputStream outputStream = null;
try {
  outputStream = getContext().getContentResolver().openOutputStream(uri);
  bitmap.compress(mCompressFormat, mCompressQuality, outputStream);
  Utils.copyExifInfo(getContext(), mSourceUri, uri, bitmap.getWidth(), bitmap.getHeight());
  Utils.updateGalleryInfo(getContext(), uri);//ERROR
  return uri;
} finally {
  Utils.closeQuietly(outputStream);
}

}

@igreenwood
Copy link
Owner

Hi,

What Uri that throws the Exception?
And can you show me the stack trace?

@JanesenGit
Copy link
Author

JanesenGit commented Nov 8, 2017

Utils.updateGalleryInfo(getContext(), uri);

If the album does not exist uri, throw "UnKown URI"

@tinsukE
Copy link
Contributor

tinsukE commented Nov 9, 2017

I believe this issue happens when you're trying to save the image to a "file:///" Uri.

On API 25, I'm getting the following exception:

java.lang.IllegalArgumentException: Unknown URI file:///data/user/0/com.getbux.android.dev/cache/image_cropped_649107509.jpg
	at android.content.ContentResolver.update(ContentResolver.java:1405)
	at com.isseiaoki.simplecropview.util.Utils.updateGalleryInfo(Utils.java:528)
	at com.isseiaoki.simplecropview.CropImageView.saveImage(CropImageView.java:1317)
	at com.isseiaoki.simplecropview.CropImageView.access$2100(CropImageView.java:58)
	at com.isseiaoki.simplecropview.CropImageView$14.run(CropImageView.java:1833)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
	at java.util.concurrent.FutureTask.run(FutureTask.java:237)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
	at java.lang.Thread.run(Thread.java:761)

By checking ContentResolver's code, we see:

    public final int update(@RequiresPermission.Write @NonNull Uri uri,
            @Nullable ContentValues values, @Nullable String where,
            @Nullable String[] selectionArgs) {
        Preconditions.checkNotNull(uri, "uri");
        IContentProvider provider = acquireProvider(uri);
        if (provider == null) {
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
        ...
    }

and

    public final IContentProvider acquireProvider(Uri uri) {
        if (!SCHEME_CONTENT.equals(uri.getScheme())) {
            return null;
        }
        ...
    }

So, com.isseiaoki.simplecropview.util.Utils.updateGalleryInfo() will only succeed if the Uri is a content based one.

I'll be creating a PR with a suggested fix.

@tinsukE
Copy link
Contributor

tinsukE commented Nov 9, 2017

@IsseiAoki actually, I don't think I can create a PR without breaking your workflow.

If I see it correctly, you'd first create a 1.1.7 branch, push the fix there, along with the changelog/readme/gradle changes.

Only after that you'd merge that branch to master.

So, if you create a 1.1.7 branch, I can create a PR of mine (https://github.com/tinsukE/SimpleCropView/tree/1.1.7) towards it.

@igreenwood
Copy link
Owner

@JanesenHeart Thank you for your response.

@tinsukE
Thank you very much for your suggestion and contribution. Your kind explanation was really easy to understand.
I have created 1.1.7 branch and have pushed it. If you create PR, I will review it and merge to master, then release it : )

@tinsukE
Copy link
Contributor

tinsukE commented Nov 9, 2017

Done!

@igreenwood
Copy link
Owner

Thank you for your contribution! 🎉
I will review and release it today.

@igreenwood igreenwood mentioned this issue Nov 10, 2017
@igreenwood
Copy link
Owner

@tinsukE
I have merged your changes and released it. Thank you👍

@JanesenHeart
1.1.7 has been released. Please check it : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants