I'm making an Android application where I want the user to read a byte[] as an audio file. My SDK version is 24. So first I record my byte[] inside a file:
public void enregistrerFichierAudio(byte[] b) {
File test = new File("LOCAL_FILE.txt");
try{
FileOutputStream fos = new FileOutputStream(test);
fos.write(b);
fos.close();
} catch(Exception e){}
}
And then I try to open an audio intent with the piece of code below:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("LOCAL_FILE.txt");
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Unfortunately I have the following error:
FATAL EXCEPTION: main
Process: com.refereetimer.TimerMyActivity, PID: 20842
android.os.FileUriExposedException: file:///LOCAL_FILE.txt exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
Someone know why I have this error? Thanks for reading this message.