Android – Best Practice – Adding your App to the Android Share Menu

androidandroid-intent

My App sends files(all mime Types) over a TCP connection and hence I wanted my app to appear in the Android Share menu.

I added the following intent filters to my Activity in AndroidManifest.xml

<intent-filter ><!--intent filter for single file sharing-->
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="*/*" />
</intent-filter>
<intent-filter ><!--intent filter for sharing multiple files-->
    <action android:name="android.intent.action.SEND_MULTIPLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="*/*" />
</intent-filter>

Now I added this to the Activity which is to be launched on clicking the Share Action

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<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
    if (uris != null) {
        fileset = new HashSet();
        for(Uri uri : uris) {
            fileset.add(getPathfromUri(uri));
        }
    }
}

I use this method to generate the absolute paths of the Files that are to be shared.

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;
}

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?

In Addition to the Share menu, there is a Send Via menu on my Phone.
screenshot

Is there a way to get my App into this list?

Best Answer

I've outlined it here how to get in the menu:

http://blog.blundellapps.com/add-your-app-to-the-android-menu/

Basically it's having your mimetype / :

        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="*/*" />
        </intent-filter>

If you do that and it doesn't show up, it means they are using an intent menu and it's a custom share list so you cannot force your way in.