Java 我需要将audio.mp3从我的应用程序共享到Whatsapp
当我运行应用程序时,它不会在whatsapp中共享音频Java 我需要将audio.mp3从我的应用程序共享到Whatsapp,java,android,android-intent,Java,Android,Android Intent,当我运行应用程序时,它不会在whatsapp中共享音频 pulsante2.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { //condividere InputStream inputStream; FileOutputStream fileOutputStream; try { inputStr
pulsante2.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//condividere
InputStream inputStream;
FileOutputStream fileOutputStream;
try {
inputStream = getResources().openRawResource(R.raw.suono2);
fileOutputStream = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "sound.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("file://" + Environment.getExternalStorageDirectory() + "/sound.mp3" ));
intent.setType("audio/mpeg");
startActivity(Intent.createChooser(intent, "Share audio"));
return false;
}
});
我添加了
那么为什么它不共享音频mp3呢?也许URI是错误的?您可以尝试使用
Uri.fromFile(Environment.getExternalStorageDirectory()+“/sound.mp3”)
?fileOutputStream=newfileoutputstream(新文件(Environment.getExternalStorageDirectory(),“sound.mp3”))或Uri.parse(文件:/“+Environment.getExternalStorageDirectory()+”/sound.mp3”);在第二个示例中,无法应用java.lang.string中的“说我”错误Uri