Well, the correct way of doing it is by using FileProvider
(as mentioned in developer). But I have figured out a naughty way to do it without adding FileProvider
. It is obviously a workaround but it works.
In your Activity, add the following lines:
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
This will simply ignore the URI exposure and you will get the access.
Yes, I know that this is not the best practice. But I just wanted to provide an alternative to it.
Still, recommended way is by using FileProvider
.