Share audio file (.mp3) via Facebook, email, and SMS/MMS

14,055

Solution 1

There is no option for Facebook, but you can share email and MMS with Bluetooth. Here is my code. Take a look if it helps you:

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///"+mypath));
startActivity(Intent.createChooser(share, "Share Sound File"));
break;

Here my path is the path of the sound file on the SD card.

Solution 2

File f=new File("full audio path");
Uri uri = Uri.parse("file://"+f.getAbsolutePath());
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("audio/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(share, "Share audio File"));

Solution 3

You are trying to share an mp3 over services that don't support it.

  • Facebook supports text, pictures and videos.
  • SMS is plain text (and only very short plain text)
  • MMS does support audio, but (as far as I can tell from observation (i.e. without reading the spec)) only very low bit rate audio in some format that usually comes in a file with a .3g extension

The apps do not show up in the list of supported apps for mp3 because they are not supported.

Share:
14,055

Related videos on Youtube

Kartik Domadiya
Author by

Kartik Domadiya

Google Cloud Platform Google App Engine Google For Workspace Angular Angular JS Mobile Platform - Android & iOS Python Java PHP HTML5

Updated on June 04, 2022

Comments

  • Kartik Domadiya
    Kartik Domadiya almost 2 years

    I have an audio file (.mp3) and some information related to it. I want to share with Facebook, E-mail, SMS/MMS, etc..

    What I have done is: when user clicks on the share button, it pops up list of all supported applications that can handle this Intent. But this does not show Facebook and SMS/MMS options.

    Here is my code..

    public void shareWithFriends(int resId)
    {
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("audio/mp3");
        share.putExtra(Intent.EXTRA_SUBJECT,"Ringtone File : "+ getResources().getResourceEntryName(resId)+".mp3");
        share.putExtra(Intent.EXTRA_TEXT,"Ringtone File : "+getResources().getResourceEntryName(resId)+".mp3");
        share.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.my.android.soundfiles/"+resId));
        share.putExtra("sms_body","Ringtone File : "+ getResources().getResourceEntryName(resId)+".mp3");
        startActivity(Intent.createChooser(share, "Share Sound File"));
    }
    

    Here are some results:

    1. When I use MIME type audio/mp3, only the email options pops up. No Facebook and SMS/MMS share.

    2. When I use MIME type */*, Email and SMS options pops up. No Facebook option is there.

    Here it is interesting to note that when I click on the SMS option, only text appears. I don't see any MP3 file attached (the same thing happens in Whatsapp (as I have Whatsapp installed on my phone). However, when I click on any mail application (for example, Gmail or Yahoo mail) it shows me the MP3 file attached.

    Where am I going wrong?

  • Kartik Domadiya
    Kartik Domadiya over 12 years
    Thanks for the very quick response. So final result would be like "i cannot share my audio file to Facebook."
  • Quentin
    Quentin over 12 years
    Not using their standard interface. Going via an app might make it possible. It is probably worth investigating AudioBoo.
  • Kartik Domadiya
    Kartik Domadiya over 12 years
    I see Whatsapp option, but when i select that app, it doesnot attach my audio file. What can be the reason for that. However when i select any mail app.(Gmail or YahooMail),i see the attached file and again i can see the mail is sent with necessary attachments.