我试图创建一个共享音频文件的按钮。我得到了不支持的文件格式错误。我尝试了所有类型,但始终给出相同的错误(音频/ mpeg,音频/ aac,音频/ wav,音频/ ogg,音频/ midi,音频/ x-ms-wma) 这是我的密码
button.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
File f = new File("ses.mp3");
Uri uri = Uri.parse("file://" + f.getAbsolutePath());
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("audio/mp3");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mactivity.startActivity(Intent.createChooser(share, "Share audio File"));
Toast.makeText(getApplicationContext(), "Song Shared Successfully", Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:0)
我不确定,但是尝试使用此Intent
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("*/*");
File imageFileToShare = new File(f.getAbsolutePath());
Uri uri= FileProvider.getUriForFile
(mactivity,mactivity.getPackageName()+".provider",imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
mactivity.startActivity(Intent.createChooser(share,“共享音频文件”));