SolveduCrop FileUtils NumberFormatException

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

What is the current behavior?
Throwing exception when selected an image from Downloads folder

What is the expected behavior?
Process the image properly

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Just copy some image to /sdcard/Download folder and try to open with through the app

Please attach any image files, URL and stack trace that can be used to reproduce the bug.

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #6 Process: br.com.saibala.novelo, PID: 7256 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:325) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.NumberFormatException: For input string: "raw:/storage/emulated/0/Download/vm.png" at java.lang.Long.parseLong(Long.java:590) at java.lang.Long.valueOf(Long.java:804) at com.yalantis.ucrop.util.FileUtils.getPath(FileUtils.java:159) at com.yalantis.ucrop.task.BitmapLoadTask.processInputUri(BitmapLoadTask.java:171) at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:90) at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:41) at android.os.AsyncTask$2.call(AsyncTask.java:305) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)  at java.lang.Thread.run(Thread.java:764) 

Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop?

2.2.0. I've never tried that in previous versions.

14 Answers

✔️Accepted Answer

This is not a complete solution, just nothing will happen. But I think users should be able to open files from Downloads directory. So I completed it with following code:

final String id = DocumentsContract.getDocumentId(uri);
        if (!TextUtils.isEmpty(id)) {
            if (id.startsWith("raw:")) {
                return id.replaceFirst("raw:", "");
            }
            try {
                final Uri contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
                return getDataColumn(context, contentUri, null, null);
            } catch (NumberFormatException e) {
                 return null;
            }
      }

Other Answers:

I am facing same issue. I am Android Q.
The id from code
final String id = DocumentsContract.getDocumentId(uri);

returns msf:19106.

I tried using integer part from the string but still does not upload correct photo.
Any solutions?

So is this an Android bug that we have to do this for "raw:" ?

What is the solution??
If I do like
if (id.startsWith("msf:")) {
return id.substring(4);
}, it is not solving the problem. Nothing is happening. What is the resolution?

any solution?

I also meet this issue, the uri contains "msf:***" and it fix it :

public static String getImagePathFromURI(Context context, Uri uri) {
        Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
        String path = null;
        if (cursor != null) {
            cursor.moveToFirst();
            String document_id = cursor.getString(0);
            document_id = document_id.substring(document_id.lastIndexOf(":") + 1);
            cursor.close();

            cursor = context.getContentResolver().query(
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
            if (cursor != null) {
                cursor.moveToFirst();
                path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
                cursor.close();
            }
        }
        Log.d(TAG,"getImagePathFromURI " + path);
        return path;
    }

I am facing same issue. I am Android Q.
The id from code
final String id = DocumentsContract.getDocumentId(uri);

returns msf:19106.

I tried using integer part from the string but still does not upload correct photo.
Any solutions?

Same here.

On Android Q final String id = DocumentsContract.getDocumentId(uri); returns msf:36929

More Issues: