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

余生长醉 提交于 2019-11-29 08:22:52
Mohit marwal

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.

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.

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

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

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"));
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"));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!