title: Sharing the audio file located on an url with other apps in android
body: <p>My android application has mp3 files sitting on the amazon s3 bucket. I have an URL to access that audio clip. I am able to play the audio clip using MediaPlayer by passing the URL to the data source of the media player.</p>
  
  <p>I am creating an application which lets the user share audio clips from my app to other IM apps like whatsapp. So, I will provide a share widget on the Activity and upon cliking on that widget then whatsapp should be opened and the user should be able to select a contact to which he wants to share the audio clip. </p>
  
  <p>For this I need to download the audio clip to local storage system and then share the file with other app using ContentURI. However I am unable to figure out what is the best way to do it.</p>
  
  <p>As per Android documentation the below code canbe used to send binary files:</p>
  
  <pre><code>Intent shareIntent = new Intent();
  shareIntent.setAction(Intent.ACTION_SEND);
  shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
  shareIntent.setType("image/jpeg");
  startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
  </code></pre>
  
  <p>I am assuming that audio files are binary files. So, I am using the below code to send the audio clip.    </p>
  
  <pre><code>Intent intent = new Intent(android.content.Intent.ACTION_SEND);
  intent.putExtra(Intent.EXTRA_STREAM, uriToImage);
  intent.setType("audio/mpeg3");
  startActivity(intent);
  </code></pre>
  
  <p>Looks like the only piece I am missing here is "uriToImage". Can anyone help me understand how to get the "uriToImage" for the resource located at a URL. ?</p>
  
  <p>Updated the code as per CommonsWare's comment. Below is the updated code:</p>
  
  <pre><code>Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                  Uri contentUri = Uri.fromFile(new File(clipAudioUrl));
                  intent.putExtra(Intent.EXTRA_STREAM, contentUri);
                  intent.setType("audio/mpeg");
                  intent.setPackage("com.whatsapp");
                  startActivity(intent);
  </code></pre>
  
  <p>Upon touching the share widget Watsapp is being opened directly(Which is what I want), however the share is familing with the error "Share failed". I am assuming that it is because of the uri for which I have used the below code:</p>
  
  <pre><code>Uri contentUri = Uri.fromFile(new File(clipAudioUrl));
  </code></pre>
  
  <p>As per CommonsWare's comment, whatsapp also expect the URI to be either in the format "file:\" or "content:\"</p>
  
  <p>Could you please help me convert the URL in the format of either "file:\" or "content:\". Thank you.</p>