问题
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