AndroidUtilCode: Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3033
Describe the bug
A clear and concise description of what the bug is.
- The version of utilcode: 1.23.7
- The device: 小米6
- The version of device: API 26
The code of bug
UriUtils.uri2File
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 111 && data != null) {
if (resultCode == Activity.RESULT_OK) {
Uri uri = data.getData();
File file = UriUtils.uri2File(FilePickerActivity.this, uri);
String absolutePath = file.getAbsolutePath();
}
}
}
The stack of crash
2019-03-08 14:15:38.213 8143-8143/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.wiki.cc, PID: 8143
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/document/3033 flg=0x1 }} to activity {com.wiki.cc/com.wiki.cc.ui.a.FilePickerActivity}: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3033
at android.app.ActivityThread.deliverResults(ActivityThread.java:4391)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4434)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1678)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6701)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/3033
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
at android.content.ContentResolver.query(ContentResolver.java:756)
at android.content.ContentResolver.query(ContentResolver.java:705)
at android.content.ContentResolver.query(ContentResolver.java:663)
at com.wiki.cc.util.UriUtils.getFileFromUri(UriUtils.java:120)
at com.wiki.cc.util.UriUtils.getFileFromUri(UriUtils.java:113)
at com.wiki.cc.util.UriUtils.uri2File(UriUtils.java:79)
at com.wiki.cc.ui.a.FilePickerActivity.onActivityResult(FilePickerActivity.java:53)
at android.app.Activity.dispatchActivityResult(Activity.java:7310)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4387)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4434)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1678)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6701)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (11 by maintainers)
同样的问题
选择
下载
里的文件,uri 为content://com.android.providers.downloads.documents/document/239
使用UriUtils.uri2File(uri)
会崩溃 但使用https://github.com/coltoscosmin/FileUtils/blob/master/FileUtils.java
可以正常运行