0

i want to share audio file with social media like whatsapp,drive,gmail,etc. i tried this code,

  1. after i click on the whatsapp icon i get the massage: "the file format is not supported"
  2. after i click on the gmail icon i get the massage: "Couldnt attach file"
    //sharePath: my audio path file
    String sharePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + songNameAndDateArray.get(newI).getSongName().toString() + "FinalSongRec" + "File" + "AudioRecording.3gp";
    File f = new File(sharePath);
    Uri uri = Uri.parse(f.getAbsolutePath());
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("audio/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(shareIntent,"share audio");

Umair Khan
  • 1,684
  • 18
  • 34

1 Answers1

0

Check following code

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

I found this answer from following link Sharing audio file