Sharing audio file

Below code worked for me

    SoundFiles soundFiles=.....
    String FullFilePath=soundFiles.getPath();
    Uri uri = Uri.fromFile(new File(FullFilePath));
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("audio/*");
    share.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(share, "Share Sound File"));

Oké, found out what I did wrong. For people who have the same problem, this is how I solved it:

I forgot to parse the String to an uri. Thats the only line of code I had to add. Uri uri = Uri.parse(sharePath);

Here is the full rest:

    String sharePath = Environment.getExternalStorageDirectory().getPath()
            + "/Soundboard/Ringtones/custom_ringtone.ogg";
    Uri uri = Uri.parse(sharePath);
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("audio/*");
    share.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(share, "Share Sound File"));

Also do not forget to add permission WRITE_EXTERNAL_STORAGE otherwise you'll get an error while running your application.


This is my way.

Uri uri = Uri.parse("file://" + sharePath);