I am getting IllegalArgumentException during picking a document file from download manager ,which is happening only for oreo
Asked Answered
A

1

21

Here I am attaching the logs :

   Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/1587
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:418)

I am using this code which is working fine.But for the case of download manager it is throwing exception at first line of 'try' block

 Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;

I already tried this: Android getting file path from content URI using contentResolver and this: java.lang.IllegalArgumentException: Unknown URI content and some others related to this question but not any one of them resolves my problem.

Andvari answered 1/10, 2018 at 13:11 Comment(6)
Are you getting all the things required in the line query(uri, projection, selection, selectionArgs, null); ?Natica
uri , projection i am sending but selection and selctionArgs are null, i don't think that will create problemAndvari
Seems like your URI is invalid.Natica
yeah i know ,but how come this is working fine for other versionsAndvari
I think the best option would be to use DocumentTreeNatica
@AjayChauhan Did you get any solution? Please help me out for the same. I'm also getting the same error.Glasscock
R
19

I was getting the same error Unknown URI: content://downloads/public_downloads. I managed to solve this by changing contentUri and by using InputStream methods to fetch file from Download directory. In some of devices changing contentUri to content://downloads/my_downloads works. Checkout this answer for full solution.

Rociorock answered 27/10, 2018 at 12:1 Comment(8)
Just out of curiosity, did you also only get this on devices running 8.0? I recently started getting this in crashlytics with devices running 8.0Cacoepy
Yes, this issue is from android 8.0Halland
I am facing this issue with Flutter Image picker. How can this be solved?Actinal
You have to manually change couple of lines of code in Image picker by yourself as described in link in answer.Rociorock
I created a gist that fixes this issue - gist.github.com/HBiSoft/15899990b8cd0723c3a894c1636550a8Cacoepy
@Cacoepy your gist code works fine in all devices. thanks.Ferous
I'm getting error in a variable 'filename' around line 94. :(Venerable
@KoushikShomChoudhury error is fixed, commenting to let other know it is working (tested 08.01.20)Pothouse

© 2022 - 2024 — McMap. All rights reserved.