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.
Is there a way to get my App into this list?
Use Sharedr for More Share Menu Options Tap the Invoke Share Dialog button and you'll see an Android prompt to choose Android System or Sharedr. Choose the latter, followed by Always to set it as the default. Now, you'll see the Sharedr interface anytime you tap the share button around your phone.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With