【问题标题】:How can I share a sound to whatsapp in Android Studio?如何在 Android Studio 中向 whatsapp 分享声音?
【发布时间】:2017-06-22 00:37:36
【问题描述】:

我试过这样:

shareBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {



                final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
                shareIntent.setType("audio/mp3");
                shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://com.example.aaron.sharetest/sound.mp3"));
                startActivity(Intent.createChooser(shareIntent, "Sound shared!"));

但这不起作用,whatsapp告诉我再试一次。

我在this stackoverflow question的回答中也发现了这种方式:

String sharePath = Environment.getExternalStorageDirectory().getPath()
        + "/Soundboard/Ringtones/custom_ringtone.ogg";
Uri uri = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Sound File"));

在我的情况下,我必须写什么来代替这个?:

Environment.getExternalStorageDirectory().getPath()
            + "/Soundboard/Ringtones/custom_ringtone.ogg" 

我的 sound.mp3 文件位于 raw 文件夹中

【问题讨论】:

  • 您的音频文件在哪里?
  • @jagapathi 在原始文件夹中

标签: java android audio resources share


【解决方案1】:

您可以使用此代码共享原始文件夹文件

名称 = 文件名

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
share.setType("audio/*");
 sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(
        "android.resource://"+ this.getPackageName()+"/raw/" + name
));
startActivity(Intent.createChooser(sharingIntent, "Share via"));

【讨论】:

  • 如果我点击whatsapp它仍然显示“分享失败,请重试”
  • 检查它让你知道我什么时候找到了溶胶
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多