I have various audio files in the raw folder in my Android project. My code is not working. When I click the share button application, it crashes.
This is my code:
public void onClick(View v) {
    InputStream inputStream;
    FileOutputStream fileOutputStream;
    try {
        inputStream = getResources().openRawResource(R.raw.numer_1);
        fileOutputStream = new FileOutputStream(
            new File(Environment.getExternalStorageDirectory(), "sound.mp3"));
        byte[] buffer = new byte[1024];
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            fileOutputStream.write(buffer, 0, length);
        }
        inputStream.close();
        fileOutputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_STREAM,
    Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/sound.mp3" ));
    intent.setType("audio/*");
    startActivity(Intent.createChooser(intent, "Share sound"));
}
And Android manifest add:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />