我在从下载管理器中选择文档文件时遇到 IllegalArgumentException,这只发生在 oreo
I am getting IllegalArgumentException during picking a document file from download manager ,which is happening only for oreo
我在这里附上日志:
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)
我正在使用这段代码 fine.But 对于下载管理器,它在 'try' 块的第一行抛出异常
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;
我已经试过了:Android getting file path from content URI using contentResolver
还有这个:java.lang.IllegalArgumentException: Unknown URI content 和其他一些与这个问题相关的问题,但没有一个能解决我的问题。
我遇到了同样的错误 Unknown URI: content://downloads/public_downloads
。我设法通过更改 contentUri 和使用 InputStream
方法从下载目录中获取文件来解决这个问题。在某些设备中,将 contentUri 更改为 content://downloads/my_downloads
是可行的。 Checkout this answer for full solution.
我在这里附上日志:
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)
我正在使用这段代码 fine.But 对于下载管理器,它在 'try' 块的第一行抛出异常
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;
我已经试过了:Android getting file path from content URI using contentResolver 还有这个:java.lang.IllegalArgumentException: Unknown URI content 和其他一些与这个问题相关的问题,但没有一个能解决我的问题。
我遇到了同样的错误 Unknown URI: content://downloads/public_downloads
。我设法通过更改 contentUri 和使用 InputStream
方法从下载目录中获取文件来解决这个问题。在某些设备中,将 contentUri 更改为 content://downloads/my_downloads
是可行的。 Checkout this answer for full solution.