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

Ajay Chauhan picture Ajay Chauhan · Oct 1, 2018 · Viewed 11.9k times · Source

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.

Answer

karanatwal.github.io picture karanatwal.github.io · Oct 27, 2018

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.