0

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 :

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

Community
  • 1
  • 1
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119

1 Answers1

1

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

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

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I want just a file path,not a content. – Sergey Shustikov Nov 17 '14 at 12:23
  • @SergeyShustikov: Your statement is akin to saying that you "want just a file path" for an HTTP URL. Talented programmers know that you do not have direct file access to a Web server, but instead need to open an `InputStream` and download a file pointed to by that URL. `Uri` values are much the same. There is no requirement for any `ContentProvider` to give you a `Uri` that points to a file, let alone a file that you can access, let alone with some deterministic conversion between the `Uri` and a local file path that you can access. – CommonsWare Nov 17 '14 at 12:37