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();
}
});
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"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.