How to create your own “Share” application for photos


This is alot easier to do than you might believe, it’s even so easy to do, that you might find it hard to find information about it in the documentation.

The main thing you have to do is to register your application to receive the SEND intent which is sent when clicking the “Share” button.

Add this to your Activity in the AndroidManifest.xml

<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <data android:mimeType="image/*" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Then you automatically get your application registered to the Sharing-list with the application name and icon, when selecting the application in the list, the activity will be launched and the photo is easily retreived through the launching intent.

final Intent intent = getIntent();
final Bundle content = intent.getExtras();
if ( content != null ) {
        //The uri below till contain an uri to the contentprovider
	final Uri uri = (Uri)content.getParcelable(Intent.EXTRA_STREAM);
 
        //if you want to know the filename of the image, just do a managedQuery 
        //against the projection MediaStore.Images.Media.DATA
}
  1. No comments yet.
(will not be published)

  1. No trackbacks yet.