Intent.ACTION_SEND Whatsapp
我正在尝试通过 Whatsapp 分享 mp3 文件。它与 Gmail 等其他应用程序完美配合,但不适用于 Whatsapp。有人可以帮助我吗?我需要添加一些 putExtra() 吗?
这是我的代码:
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"));
}
谢谢;)
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 ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该将音频文件复制到 SD 卡,并将其作为文件共享,而不是作为 Android 资源,如下所示:
现在它应该通过 Whatsapp 工作。
You should copy your audio file to sdcard, and share it as file, not as android resource, like this:
Now it should work through whatsapp.
尝试将 MIME 类型更改为“audio/mpeg3”,以便第二行显示
Try changing the MIME type to "audio/mpeg3" so that the second line reads
WhatsApp 还接受 OGG 格式:
WhatsApp also accepts OGG format:
您必须将其包含在代码中:
You have to Include this in you code: