I am developing an app that allows to share an audio file with whatsapp.
I'm using this code:
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/raw/song.mp3");
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("audio/mp3");
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_STREAM, uri);
try {
startActivity(waIntent);
}catch (android.content.ActivityNotFoundException ex){
Toast.makeText(Fung.this,"Please, install Whatsapp", Toast.LENGTH_LONG).show();
}
But when whatsapp starts and I try send to a person, this error is displayed: "Fail to share, please try again".
When I change this code to send a text, it work, but not with audio file. Someone have anyone idea why this happens and how fix it?