【发布时间】:2021-01-25 05:03:32
【问题描述】:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an file is picked
if (requestCode == 3 && resultCode == RESULT_OK && null != data) {
Uri uri = data.getData();
InputStream is = getContentResolver().openInputStream(uri);
}
else {
Toast.makeText(this, "You haven't picked any file", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
Log.d("EXCEPTION_ERROR",e.toString());
e.printStackTrace();
}
}
我试过了。我添加了更多源代码。但是,inputStream 给出了错误。
EXCEPTION_ERROR: java.io.FileNotFoundException: 没有这样的文件或目录
System.err: java.io.FileNotFoundException: 没有这样的文件或目录
System.err:在 android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)
乌里:
content://com.android.providers.downloads.documents/document/3356
content://com.android.providers.downloads.documents/document/3331
【问题讨论】:
-
uri的值是多少?或许您应该记录它以便您可以看到它。
-
我不知道android,但是内容是像文件和http这样的真正的内容类型吗?
-
@NomadMaker
uri和url之间有区别 -
是的,我知道。对不起,这该死的手机上的拼写检查器找到了我。但是内容是 uri 可接受的方案吗?
-
没有。只需使用文件应用程序或其他文件管理器应用程序。转到同一个文件并尝试让它打开。