5

Im trying to share a mp3 file through whatsapp. It works perfectly with other apps like gmail, but it dosent works on whatsapp. Can anyone help me? Do I need to add some putExtra()?

Here's my code:

public void shareWithFriends(int id)
{       
  Intent share = new Intent(Intent.ACTION_SEND);
  share.setType("audio/mp3");
  //share.putExtra(Intent.EXTRA_SUBJECT,"subject");
  //Uri uri = Uri.parse("android.resource://com.igs.pokemonsoundboard/" + id);
  Uri uri = Uri.parse("android.resource://com.igs.pokemonsoundboard/raw/" + R.raw.pikachump3);
  share.putExtra(Intent.EXTRA_STREAM,uri);
  //share.putExtra("sms_body","Ringtone File :");
  startActivity(Intent.createChooser(share, "Share sound"));
}

Thanks ;)

user1116665
  • 85
  • 1
  • 2
  • 6

4 Answers4

6

You should copy your audio file to sdcard, and share it as file, not as android resource, like this:

final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("audio/mp3");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://"+path+filename));
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_sound)));

Now it should work through whatsapp.

Bertrand Marron
  • 21,501
  • 8
  • 58
  • 94
carlospiles
  • 407
  • 4
  • 8
  • 2
    This code is not working for me, I'm getting the `Failed to send, please try again` message, even though I have saved the file in `sdcard` – alvaro.delaserna Dec 17 '14 at 11:19
0

WhatsApp also accepts OGG format:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("audio/ogg");
shareIntent.putExtra(Intent.EXTRA_STREAM, getSoundUri());
startActivity(shareIntent);
Toni Alvarez
  • 1,012
  • 1
  • 10
  • 21
0

You have to Include this in you code:

sendIntent.setPackage("com.whatsapp");
ashif-ismail
  • 1,037
  • 17
  • 34
0

Try changing the MIME type to "audio/mpeg3" so that the second line reads

share.setType("audio/mpeg3")
SeanPONeil
  • 3,901
  • 4
  • 29
  • 42