简体   繁体   中英

Error when accessing downloaded files on Android

I'm running into a problem in my Android Application where whenever I tried to load a file that I have downloaded from email, I'm receiving a java.io.FileNotFoundException error. This is weird, because the file is clearly showing up in the "Downloads" list, but it does not seem to be found when my app tries to open it. The error references a "/document" directory which does not physically exists on the device. This sort of seems like it could be related to some mechanism for passing files via intents, but I'm missing something. I am trying this on both a Samsung Galaxy Tab 4 running 4.4.2 as well as different versions of the Android Emulator. I'm getting the same problem everywhere I look. Below, I have included the error message.

Any help with this would be appreciated.

Thanks!!!

11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: File select error 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: java.io.FileNotFoundException: /document/1677: open failed: ENOENT (No such file or directory) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at libcore.io.IoBridge.open(IoBridge.java:409) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at java.io.FileInputStream.(FileInputStream.java:78) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at java.io.FileReader.(FileReader.java:42) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at com.xxxxxx.yyyyyyyyy.ImportActivity.onActivityResult(ImportActivity.java:210) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at android.app.Activity.dispatchActivityResult(Activity.java:5643) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at android.app.ActivityThread.delive rResults(ActivityThread.java:3677) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at android.app.ActivityThread.handleSendResult(ActivityThread.java:3724) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at android.app.ActivityThread.access$1400(ActivityThread.java:175) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at android.os.Handler.dispatchMessage(Handler.java:102) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at android.os.Looper.loop(Looper.java:146) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at android.app.ActivityThread.main(ActivityThread.java:5602) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at java.lang.reflect.Method.invokeNative(Native Method) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyy yyyy E/ImportActivity: at java.lang.reflect.Method.invoke(Method.java:515) 11-07 23:23:13.324 12193-12193/com.xxxxxx.yyyyyyyyy E/ImportActivity: at

 /document/1677

That is not a file system path but a part of a content provider path.

You will see the complete path with url.getPath().

You can open an input stream to the document with

getContentResolver.openStream(url);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM