Kartik Domadiya
Kartik Domadiya

Reputation: 29968

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

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?

Upvotes: 3

Views: 14606

Answers (7)

user3187035
user3187035

Reputation:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("audio/*");
        sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,
                Uri.fromFile(new File("filepath")));            
        startActivity(Intent.createChooser(sharingIntent,"Share using"));

Upvotes: 2

Pradip
Pradip

Reputation: 316

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"));

Upvotes: 2

Narendra Sorathiya
Narendra Sorathiya

Reputation: 3830

String sharePath = Environment.getExternalStorageDirectory().getPath()
    + "/Soundboard/Ringtones/custom_ringtone.ogg";
Uri uri = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Sound File"));

Upvotes: 0

Hardik Joshi
Hardik Joshi

Reputation: 9507

Use following code its working for me to share audio via intent.

String path = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + "/abc.mp3";


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

Upvotes: 0

Quentin
Quentin

Reputation: 943207

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.

Upvotes: 2

Harshid Vasoya
Harshid Vasoya

Reputation: 5721

You are try this.

 final Intent sendIntent  = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra("sms_body", "bod of sms");
            sendIntent.setType("*/*");
            sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
            final File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.amr");
            Uri uri = Uri.fromFile(file1);
            Log.e("Path", "" + uri);
            sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(Intent.createChooser(sendIntent, ""));

Upvotes: 0

Mohit marwal
Mohit marwal

Reputation: 251

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.

Upvotes: 10

Related Questions