Android: Create your own sharing app

One of the first applications I did for Android was a very simple application which simply takes a picture using Camera and then send it to a remote server. Very simple, but it introduced to me into the android world and the notion of activities and communication between different applications.
A little addition to this application I wanted to make was the possibility to share any of the pictures already taken. To do that I wanted to add the application to the list of the choices which appear when an user click on the “share” button when view an image using the default Gallery application.

Nothing easier than that! It was just a matter of a couple of tags to be added to the AndroidManifest.xml and the trick was done!
Here the manifest:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
< ?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.aviary.app.AviaryPhoto" android:versionCode="1"
   android:versionName="1.0">
   <application android:icon="@drawable/icon" android:label="@string/app_name"
      android:debuggable="true">
      <activity android:name=".MainActivity" android:label="@string/app_name"
         android:theme="@android:style/Theme.NoTitleBar"
         android:screenOrientation="landscape">
         <intent -filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent>
      </activity>

      <activity android:name=".MainActivity" android:label="@string/app_name"
         android:theme="@android:style/Theme.NoTitleBar"
         android:screenOrientation="landscape" android:icon="@drawable/icon">
         <intent -filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
         </intent>
      </activity>

      <activity android:name=".MainActivity" android:label="@string/app_name"
         android:theme="@android:style/Theme.NoTitleBar"
         android:screenOrientation="landscape" android:icon="@drawable/icon">
         <intent -filter>
            <action android:name="android.intent.action.CHOOSER" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
         </intent>
      </activity>
   </application>
   <uses -sdk android:minSdkVersion="7" />
   <uses -permission android:name="android.permission.CAMERA" />
   <uses -permission android:name="android.permission.INTERNET" />
   <uses -permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

The tricky part is to add the two actions android.intent.action.SEND and android.intent.action.CHOOSER to the manifest, and the system will do the rest. In this way, when a user will select the application from the sharing list a new activity will be launched and it will just a matter of checkin which intent has been sent to get the image uri which has to be shared:

1
intent.getAction().equals( Intent.ACTION_SEND )

This is a screenshot of the device when the “share” button has been pressed

Lead Android developer at Aviary and New Yorker since 2011. Mixed marketing and artistic background with more than 10 years of experience with Flash actionscript and python before switching to android development.
  • Joevolcano

    Doesnt seem to work on the emulator…

  • Bhabani Android

    Works great……
    Thanks Buddy

  • Amit hooda

    i want to share app so i want a share button so that i can share it on facebook and twitter ,,
    i didnt get you after adding these SEND and CHOOSER wat i xactly need to do,,,
    any help is appriciated thank you

  • Vineelaredd

    can u send the source code of above

  • Amit Hooda

    @Vineelaredd

    the above given things is source code only, :)

  • Mandici Szilard

    and how can you get the selected images? or their path?
    Thank you

  • nani

    this will appear in all apps i want this app only how it work only one app ca you send me.