Intent.ACTION_SEND Whatsapp

发布于 2024-12-22 23:10:06 字数 662 浏览 1 评论 0原文

我正在尝试通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧街凉风 2024-12-29 23:10:07

您应该将音频文件复制到 SD 卡,并将其作为文件共享,而不是作为 Android 资源,如下所示:

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

现在它应该通过 Whatsapp 工作。

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.

白衬杉格子梦 2024-12-29 23:10:07

尝试将 MIME 类型更改为“audio/mpeg3”,以便第二行显示

share.setType("audio/mpeg3")

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

share.setType("audio/mpeg3")
伪心 2024-12-29 23:10:07

WhatsApp 还接受 OGG 格式:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("audio/ogg");
shareIntent.putExtra(Intent.EXTRA_STREAM, getSoundUri());
startActivity(shareIntent);

WhatsApp also accepts OGG format:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("audio/ogg");
shareIntent.putExtra(Intent.EXTRA_STREAM, getSoundUri());
startActivity(shareIntent);
离不开的别离 2024-12-29 23:10:07

您必须将其包含在代码中:

sendIntent.setPackage("com.whatsapp");

You have to Include this in you code:

sendIntent.setPackage("com.whatsapp");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文