0

I want to attach an audio file to an email.

I am attaching it but cannot get that attachment on the receiver side. I don't know exactly which mimetype i have to use for this file.

I already tried setType("*/*"). But It still doesn't work for me. Is it even possible, and if so, then how can I?

I already found a lot here on SO as well as on Google, but still haven't gotten the right solution.

Intent email = new Intent(Intent.ACTION_SEND);

email.putExtra(Intent.EXTRA_EMAIL, new String[] {});
email.setType("image/jpeg");
email.setType("audio/mpeg3");
email.putExtra(Intent.EXTRA_SUBJECT, TAG);
email.putExtra(Intent.EXTRA_TEXT, getResources().getText(R.string.Message));

Uri uri = Uri.parse("file:///android_asset/Male_Hard_2.mp3");

email.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(email, "Choose an Email client :"));
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
Biginner
  • 243
  • 1
  • 2
  • 15

2 Answers2

1

the following link is helpful for me Attaching file in email.. the key part is

ArrayList<Uri> uris = new ArrayList<Uri>();
    for (String file : filePaths)
    {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); // intent is your email intent
Community
  • 1
  • 1
stinepike
  • 54,068
  • 14
  • 92
  • 112
0

You have to use:

startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND_MULTIPLE)
    .setType("audio/wav").setType("image/jpeg")
    .setType("message/rfc822")
    .putExtra(Intent.EXTRA_EMAIL, emails)
    .putExtra(Intent.EXTRA_SUBJECT, subject)
    .putExtra(Intent.EXTRA_TEXT, strDetails)
    .putExtra( android.content.Intent.EXTRA_STREAM, uris)
    .putExtra( android.content.Intent.EXTRA_STREAM, strAudioFilePath), "Send your email in:"));             

In the above code, strAudioFilePath is the path of the Audio file.

Chris Kempen
  • 9,491
  • 5
  • 40
  • 52
anddev
  • 3,144
  • 12
  • 39
  • 70