【问题标题】:Sound file will only share with whatsapp声音文件只会与whatsapp分享
【发布时间】:2015-11-01 08:42:42
【问题描述】:

我正在尝试在长按按钮时共享声音文件。这是我的代码:

public class Tab2 extends Fragment{

Button button1;

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.tab_2,container,false);

    button1 = (Button) v.findViewById(R.id.button1);
    button1.setLongClickable(true);

    button1.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View arg0) {
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("audio/*");

            Uri uri = Uri.parse("android.resource://test.testapp/raw/" + R.raw.sound1);
            share.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(Intent.createChooser(share, "Deel geluidje"));

            return true;
        }

    });



    return v;
  }



}

但是,当我长按按钮时,会出现分享菜单,但我只能与 WhatsApp 分享声音。任何其他应用程序都不起作用。 (Gmail 给我一条消息说''无法附加空文件''。声音是 .ogg 格式,我尝试将其转换为 .wav,但它给了我同样的问题。我做错了什么?

【问题讨论】:

    标签: android audio share


    【解决方案1】:

    您是否尝试在 setType 之后设置主题和文本

      intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
      intent.putExtra(Intent.EXTRA_TEXT, "Email Message Body");
      intent.putExtra(Intent.EXTRA_EMAIL,new String[] { "sendTo@gmail.com" });
    

    【讨论】:

    • 不起作用,它仍然显示“无法附加空文件”此外,对于其他应用(如 Google Drive)也无法解决
    • 我成功地将文件发送到 whatsapp 聊天室,它运行良好
    • 看我知道这不是一个解决方案,但尝试另一个设备,因为代码工作正常
    • 代码工作正常,是的,但它没有将文件附加到电子邮件中。它只设置主题和消息。
    • 最坏的情况是使用代码将文件从原始文件复制到 SD 卡,然后共享它,,然后再次从 SD 卡中删除它,请参阅此答案stackoverflow.com/questions/7976141/…
    猜你喜欢
    • 1970-01-01
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多