Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent.ACTION_SEND Whatsapp

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

like image 892
user1116665 Avatar asked Dec 26 '11 19:12

user1116665


People also ask

How do I intent on WhatsApp?

Android intent system Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker: Intent sendIntent = new Intent(); sendIntent.

What is the use of intent createChooser () method?

Most commonly, ACTION_SEND action sends URL of build-in Browser app. While sharing the data, Intent call createChooser() method which takes Intent object and specify the title of the chooser dialog. Intent. createChooser() method allows to display the chooser.

What is the package name of WhatsApp?

com. whatsapp is the package name for official whatsapp application.


1 Answers

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.

like image 54
carlospiles Avatar answered Oct 19 '22 11:10

carlospiles