I didn't think this would be such a difficult task to solve but I can't seem to find the answer anywhere. I'm trying to get the file path to an image after a user navigates the folders on an android device and selects the file using . Such as:
/documents/imagename.png
But every solution I've tried results in a string similar to this
/documents/image:41879
First off "image:41879" is not the name of the selected file and the number after "image:" changes per picture, but as you can see this is not what I want. I'm looking to receive the full file path including the extension.
Would any one be able to help?
I have this code run when user clicks the "choose file" button
@Override
public void onClick(View v) {
// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
// browser.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 10);
}
And below is one of the many solutions I've tried which does not obtain the file path as I want
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
TextView filename = (TextView) findViewById(R.id.filenameTextView);
Uri uri = data.getData();
String path = uri.getPath();
directory = path;
filename.setText(directory);
}
Any and all help is greatly appreciated. Thank you