首页 > 解决方案 > 通过 WhatsApp 分享原始资源“发送失败,请重试”

问题描述

我想在按住按钮时共享音频,我将 mp3 保存到外部存储然后共享它,但我有一个错误“发送失败,请重试”(类似这样,原件是西班牙语)。我能做些什么?

编码:

b0.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {

            File dest = Environment.getExternalStorageDirectory();
            InputStream in = getApplicationContext().getResources().openRawResource(R.raw.teagachas);

            try
            {
                OutputStream out = new FileOutputStream(new File(dest, "lastshared.mp3"));
                byte[] buf = new byte[1024];
                int len;
                while ( (len = in.read(buf, 0, buf.length)) != -1)
                {
                    out.write(buf, 0, len);
                }
                in.close();
                out.close();
            }
            catch (Exception e) {}

            Intent share = new Intent(Intent.ACTION_SEND);
            share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory().toString() + "/lastshared.mp3"));
            share.setType("audio/*");
            getApplicationContext().startActivity(Intent.createChooser(share, "compartiendo \"" + b0.getText() + "\""));
            return true;

        }
    });

PD:代码在 onCreate 方法中

标签: javaandroidandroid-studioshare

解决方案


推荐阅读