I'm creating a file explorer on Android Studio and I get that error message:
android.os.FileUriExposedException: file:///storage/56DC-18FD/Android exposed beyond app through Intent.getData()
The thing is that I was opening that file on SD Card (whose name is: 56DC-18FD) but somehow it searched it on storage. The same problem is with the opening files on internal storage, it is searching them on file:///sdcard/
@Override
public void onFileClicked(File file) {
Log.e("Fragment", "isDIrectory2: " + file.isDirectory());
if (file.isDirectory()){
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri mydir = Uri.parse("file://" + file.getAbsolutePath());
intent.setDataAndType(mydir,"application/*"); // or use /
startActivity(intent);
}
else {
try {
OpenFile.openFile(getContext(), file);
} catch (IOException e) {
e.printStackTrace();
}
}
}