Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...