title: How to share audio file from my app
body: <p>So I am trying to share the audio that my app creates to sound cloud from the action bar sharing icon.  When I finish recording the audio I click the icon and sound cloud does come up as an option but when I click it, it goes to sound cloud then goes back to my app right away not sharing at all. </p>
  
  <p>Here is the Record Activity where I start the saving process and the sharing process also</p>
  
  <pre><code>//convert inputstream to byte array
  public static byte[] getBytesFromInputStream(InputStream is)
  {
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      try
      {
          byte[] buffer = new byte[0xFFFF];
                  for (int len; (len = is.read(buffer)) != -1;)
              os.write(buffer, 0, len);
                  os.flush();
                  return os.toByteArray();
      }
      catch (IOException e)
      {
          return null;
      }
  }
  
  public void saveInputStream(InputStream is) throws IOException
  {
      int n = 0;
      DataInputStream in1;
      in1 = new DataInputStream(is);
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
  try 
      {
          while ((n = in1.read()) != -1) 
          {
              bos.write(n);
          }
      } 
      catch (IOException e) 
      {   
          e.printStackTrace();
      }
      ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
      bb.order(ByteOrder.LITTLE_ENDIAN);
      ShortBuffer sb = bb.asShortBuffer();
  
      for (int i = 0; i &lt; sb.capacity(); i++) {
          beatsShortList.add(sb.get(i));
      }
  }
  //add zeros to shorter audio        
  public void completeStreams(List&lt;Short&gt; l1,List&lt;Short&gt; l2)
  {
      if(l1.size() &gt; l2.size())
      {
          while(l1.size() != l2.size())
          { 
          l2.add((short)0);
          }
      }
      if(l2.size() &gt; l1.size())
      {
          while(l1.size() != l2.size())
          {
              l1.add((short)0);
          }
      }
  }
      //converts short list to short array
      public short[] buildShortArray(List&lt;Short&gt; list)
      {
          short[] arr = new short[list.size()];
          for(int i = 0; i &lt; list.size(); i++)
          {
              arr[i] = list.get(i);
          }
          return arr;
      }
      //overriding back button functionality
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          if ((keyCode == KeyEvent.KEYCODE_BACK)) {
              Log.d(this.getClass().getName(), "back button pressed");
              if(player != null)
                  player.stop();
              play_thread_running = false;
              //beat_playing_thread.stop();
              //lyrics_playing_thread.stop();
              return super.onKeyDown(keyCode, event);
          }
          return true;
      }
  
      public void showDialog()
      {
          AlertDialog.Builder alert = new AlertDialog.Builder(this);
  
          alert.setTitle("What's Your Song Name!");
          alert.setMessage("Title");
  
          // Set an EditText view to get user input 
          final EditText input = new EditText(this);
          alert.setView(input);
  
          alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
  
            mixed_file_name = input.getText().toString();
            //progress = ProgressDialog.show(getApplicationContext(), "", "Mixing and Saving...");
            mix_and_save_thread = new Thread(new Runnable() {
                  @Override
                  public void run() {
                      try 
                      {
                          Log.d("Check:","Line=&gt; 437");
                          byte[] mixed_audio = mixSound();
                          Log.d("Check:","Line=&gt; 439");
                          String fileName = getFilename();
                          FileOutputStream fout = new FileOutputStream(fileName);
                          long byteRate = RECORDER_BPP * RECORDER_SAMPLERATE * channels/8;
                          WriteWaveFileHeader(fout, mixed_audio.length+40, mixed_audio.length, RECORDER_SAMPLERATE, channels, byteRate);
                          Log.d("Check:","Line=&gt; 444");
                          fout.write(mixed_audio);
                          Log.d("Check:","Line=&gt; 446");
                          fout.close();
                          //progress.dismiss();
                      } 
                      catch (IOException e) 
                      {
                          e.printStackTrace();
                      }
                  }
              });
              mix_and_save_thread.start();
  
            }
          });
  
          alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
              // Canceled.
            }
          });
  
          alert.show();
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      /**
       * Menu item selected handler that shares the selected post
       * 
       * @param  item - menu item clicked
       * @retrun boolean
       */
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int itemId = item.getItemId();
          if (itemId == R.id.action_sharing) { sharePost(); }
  
          return super.onOptionsItemSelected(item);
      }
  
      private void sharePost() {
          File audio = new File("/meip/to/audio.wav");
          Intent intent = new Intent(Intent.ACTION_SEND).setType("audio/*");
          intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(audio));
          startActivity(Intent.createChooser(intent, "Share to"));
      }
  }
  </code></pre>