How to convert file URI to file path?

百般思念 提交于 2021-01-29 18:01:10

问题


I getting an URI when try to pick a file :

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("file/*");
    startActivityForResult(intent,FILE_MANAGER_REQUEST_CODE);

In ActivityOnResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("FilePick", "request code = " + requestCode + ", resultCode = " + resultCode);
    Log.d("FilePick", "Intent = " + data != null ? data.getData().getPath() : null);

    super.onActivityResult(requestCode, resultCode, data);
}

When i pick a file data.getData().getPath() returns

/external/file/15499

How i convert it to real file path?

Note: I read this topics :

  • Get filename and path from URI from mediastore
  • Get real path from URI, Android KitKat new storage access framework

But i think it's accessible onl;y for media content. Not for files.


回答1:


There is no "real file path". A Uri is not a File.

Please use ContentResolver and methods like openInputStream() to consume the content.



来源:https://stackoverflow.com/questions/26972539/how-to-convert-file-uri-to-file-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!