I am making a soundboard app and I need to share sound1 when button1 is long pressed. I can make the share menu com up with this code:
Button button1;
button1 = (Button) v.findViewById(R.id.button1);
button1.setLongClickable(true);
button1.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("audio/ogg");
Uri.parse("android.resource://test.testapp/" + R.raw.sound1);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://test.testapp/" + R.raw.sound1));
startActivity(Intent.createChooser(shareIntent, "Share Sound"));
return true;
}
});
return v;
}
I can share the audio file perfectly with whatsapp and Google Drive, but other apps don't work. I've read that you have to copy the files to the external storage, and share them from there. I have searched for almost two days now, but I can't find a way to do this. Other articles on Stack don't help me either :/
How do I make a directory in the external storage, copy a file (sound1.ogg) from my /raw folder to that folder, and then share that sound with another app (Gmail, Google Drive, Whatsapp, Skype etc.)?