java - 通过 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 方法中
解决方案
推荐阅读
- javascript - React - 在组件之间传递方法引用
- java - CXF 总线 - 添加具有自定义超时的 HttpConduitFeature
- node.js - 如何在 Windows 中将 npm start 添加为服务
- json - 打字稿中的 JSON 转换
- php - 显示特定尺寸的图像
- c# - 在服务器上运行时获取 AD 组列表失败
- c# - 实例化一个对象但不存储对它的引用
- javascript - 开玩笑测试 onClick() 得到错误“预期的模拟函数已被调用,但没有被调用。”
- java - Swing 应用程序 Exported Jar 扩大维度
- java - 匹配单词的正则表达式以特殊字符的组合开头和结尾