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

Exception or error:

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?

How to solve:

I tried to deal with this issue and I pretty sure that samsung’s gallery uses some custom action for sharing through that menu. Taking into account that all the listed application are preinstalled ones it’s obvious that Samsung agreed with all of the listed application developers to use it’s custom intent action.

I have also tried to contact to Samsung and they haven’t replied yet.

###

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.

###

i think you are sharing the images from outside the app. plz define the minetype in intentfiler. it is working fine at mine side.

<activity
            android:name=".SharePhotoFromOutSide"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.SEND" />

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *