尝试从路径读取时没有这样的文件或目录

时间:2017-04-04 12:04:51

标签: android retrofit

  

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                        intent.setType("file/*");
                        intent.setType("image/*");
                        intent.setType("video/*");
                      //  intent.addCategory(Intent.CATEGORY_OPENABLE);
                        startActivityForResult(intent, READ_REQUEST_CODE)
 if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            // The document selected by the user won't be returned in the intent.
            // Instead, a URI to that document will be contained in the return intent
            // provided to this method as a parameter.
            // Pull that URI using resultData.getData().
            Uri uri = null;

            if (resultData != null) {
                uri = resultData.getData();
                uri1 = uri;
                Log.i("anderwidth", "Uri: " + uri.toString());
File file = new File(uri1.getPath());
            }
        }

我正在使用android进行改造。那是怎么回事?我无法将图像和视频作为文件阅读,file.exists给我假。每次都是内容//...

如果有人下载了filemanager应用程序,它就有效,而不是下载了。

1 个答案:

答案 0 :(得分:1)

如果你想从路径'读',那么从流中打开一个InputStream和read()。

InputStream is = getContentResolver().openInputStream(uri);