title: Best Practice - Adding your App to the Android Share Menu
body: <p>My App sends files(all mime Types) over a TCP connection and hence I wanted my app to appear in the Android Share menu.</p>
  
  <p>I added the following intent filters to my Activity in <code>AndroidManifest.xml</code> </p>
  
  <pre><code>&lt;intent-filter &gt;&lt;!--intent filter for single file sharing--&gt;
      &lt;action android:name="android.intent.action.SEND" /&gt;
      &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;data android:mimeType="*/*" /&gt;
  &lt;/intent-filter&gt;
  &lt;intent-filter &gt;&lt;!--intent filter for sharing multiple files--&gt;
      &lt;action android:name="android.intent.action.SEND_MULTIPLE" /&gt;
      &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;data android:mimeType="*/*" /&gt;
  &lt;/intent-filter&gt;
  </code></pre>
  
  <p>Now I added this to the <code>Activity</code> which is to be launched on clicking the Share Action</p>
  
  <pre><code>Intent intent = getIntent();
  if (Intent.ACTION_SEND.equals(intent.getAction())) {
      Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
      if (uri != null) {
          fileset = new HashSet();
          fileset.add(getPathfromUri(uri));
      }
  } else if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
      ArrayList&lt;Uri&gt; uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
      if (uris != null) {
          fileset = new HashSet();
          for(Uri uri : uris) {
              fileset.add(getPathfromUri(uri));
          }
      }
  }
  </code></pre>
  
  <p>I use this method to generate the absolute paths of the Files that are to be shared.</p>
  
  <pre><code>public String getPathfromUri(Uri uri) {
      if(uri.toString().startsWith("file://")) {
           return uri.getPath();
      }
      String[] projection = { MediaStore.Images.Media.DATA };
      Cursor cursor = managedQuery(uri, projection, null, null, null);
      startManagingCursor(cursor);
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      cursor.moveToFirst();
      String path= cursor.getString(column_index);
      //cursor.close();
      return path;
  }
  </code></pre>
  
  <p>The above method properly retrieves the absolute path of Images/Videos and other files.Is there something that I have missed out or is there a better way of doing this?</p>
  
  <p>In Addition to the <code>Share</code> menu, there is a <code>Send Via</code> menu on my Phone.
  <img src="https://lh5.googleusercontent.com/-pJSbT22xKmU/T8OxALGhsFI/AAAAAAAACe8/Fc2odYLai8w/s800/Screenshot_2012-05-28-22-33-11.png" alt="screenshot"></p>
  
  <p>Is there a way to get my App into this list?</p>