I am trying to share a sound file when a button is long-pressed. This is my code:
public class Tab2 extends Fragment{
Button button1;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab_2,container,false);
button1 = (Button) v.findViewById(R.id.button1);
button1.setLongClickable(true);
button1.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
Uri uri = Uri.parse("android.resource://test.testapp/raw/" + R.raw.sound1);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Deel geluidje"));
return true;
}
});
return v;
}
}
However, when I long press the button, the share menu comes up, but I can only share the sound with WhatsApp. Any other app doesn't work. (Gmail gives me a message saying ''can't attach empty file''. The sound is in .ogg format, and I have tried converting it to .wav, but it gave me the same problem. What am I doing wrong?