我想通过意向分享我的原始音频.mp3文件,但我遇到了一个错误



Uri Uri=Uri.parse("content://"+context.getPackageName((+"/"+R.raw.audio(;

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.putExtra(Intent.EXTRA_STREAM, uri);
view.getContext().startActivity(Intent.createChooser(share, "Share Sound File"));

使用此代码而不是Above

InputStream inputStream;
FileOutputStream fileOutputStream;
try {
inputStream = context.getResources().openRawResource(R.raw.audio);
fileOutputStream = new FileOutputStream(
new File(Environment.getExternalStorageDirectory(), "audio.mp3"));
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
}
inputStream.close();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM,
Uri.parse(Environment.getExternalStorageDirectory() + "/audio.mp3"));
intent.setType("audio/*");
context.startActivity(Intent.createChooser(intent, "Share sound"));

最新更新