标题翻译
share audio file with whatsapp (file format not supported error)
问题
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();
}
});
英文翻译
I'm trying to make a button for sharing an audio file.I get the file format not supported error.I tried all types but always gave the same error(audio/mpeg,audio/aac,audio/wav,audio/ogg,audio/midi,audio/x-ms-wma)
here my codes
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();
}
});
答案1
得分: 0
我不太确定,但请尝试使用这个意图
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, "分享音频文件"));
英文翻译
I am not sure but try to use this 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, "Share audio File"));
专注分享java语言的经验与见解,让所有开发者获益!
评论