1

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.

Rabbit Guy
  • 1,840
  • 3
  • 18
  • 28
Bilbo
  • 11
  • 2
  • Possible duplicate of [android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()](https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed) – eugeneek Jul 26 '17 at 14:23

0 Answers0