0

I tried it like this:

shareBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {



                final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
                shareIntent.setType("audio/mp3");
                shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://com.example.aaron.sharetest/sound.mp3"));
                startActivity(Intent.createChooser(shareIntent, "Sound shared!"));

But this is not working, whatsapp tells me to try it again.

I also found this way in the answers of this stackoverflow question:

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"));

What do I have to write instead of this in my case?:

Environment.getExternalStorageDirectory().getPath()
            + "/Soundboard/Ringtones/custom_ringtone.ogg" 

My sound.mp3 file is located in the raw folder

1 Answers1

0

You can share Raw folder files using this code

name = file name

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
share.setType("audio/*");
 sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(
        "android.resource://"+ this.getPackageName()+"/raw/" + name
));
startActivity(Intent.createChooser(sharingIntent, "Share via"));
jagapathi
  • 1,635
  • 1
  • 19
  • 32