Anda di halaman 1dari 6

sign up

Stack Overflow
Questions Tags Users Badges Unanswered Ask

Read this post in our app!

18

Best Practice - Adding your App to the Android Share Menu


android

android-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

log in

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?


share

improve this question


coderplus
2,656 1 15 35

Asked
May 28 '12 at 17:14

Edited
Sep 30 '12 at 16:29

AFAIK, there is only a "Share" menu. That list may be custom, as I would expect Facebook, G+, Twitter to show up on that list otherwise if you have those installed. Jason Robinson
May 28 '12 at 17:22

I too think so as the ones in the list are default applications that come with the ROM. That must be something that Samsung has added :) Thanks for clarifying coderplus May 28
'12 at 17:24

Did you try this? intent.setType("/"); jzafrilla Nov 21 '12 at 10:50


add a comment

3 Answers

Order By

Votes

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.

share

improve this answer


rus1f1kat0R
984 1 9 16

Answered
Dec 20 '12 at 9:05

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>

share

improve this answer


habib ullah
58 8

Answered
Nov 5 '13 at 7:46

Edited
Nov 5 '13 at 7:51

I think your filter is same as mine except for the mimeType.Mine shows the share menu for all file types. The menu in my original question is a custom Samsung menu and I don't think there
is a way of getting into it by just amending the Manifest. Does mimeType photo/* exist? I would have used image/* if I was just trying to share just images en.wikipedia.org/wiki/Internet_media_type coderplus Nov 6 '13 at 1:26
/ defines the all type of file, but you can You photo/* for sharing the photos from outside the app. its working fine at mine side. habib ullah Nov 20 '13 at 8:29
add a comment

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


http://blog.blundell-apps.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.
share

improve this answer


Blundell
43.2k 20 131 163

Your Answer

Answered
Dec 20 '12 at 9:33

log in
or

Name

Email

By posting your answer, you agree to the privacy policy and terms of service.

Post Your Answer

meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app
2016 Stack Exchange, Inc

Anda mungkin juga menyukai