I'm trying to retrieve an image from the gallery and get its absolute path in order to save it to the local database. Below is the code to initialize the intent to open the gallery.
fabChooseImage.setOnClickListener(view -> {
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(i, "Select Picture"), SELECT_PICTURE);
});
Then I handle the result as such:
Uri imgUri = data.getData();
if (imgUri != null) {
ivImage.setImageURI(imgUri);
File myFile = new File((imgUri.getPath()));
mSelectedImagePath = myFile.getAbsolutePath();
Toast.makeText(AddPostActivity.this, mSelectedImagePath, Toast.LENGTH_LONG).show();
}
However, this does not seem to give the absolute path and instead returns
/document/image:5632
When in fact I want the absolute path of:
Phone/files/avatars/sample.jpg