4

So I would like to do something like:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(myMessageAsImage));
intent.putExtra(Intent.EXTRA_TEXT, "My Message");
intent.setType("text/plain"); // or intent.setType("image/<imageType>");

However the documentation for ACTION_SEND doesn't seem to make this seem possible. Is there an agreed upon way to do this?

Greg Giacovelli
  • 10,164
  • 2
  • 47
  • 64
  • You forgot to tell us what will consume this Intent(your activity/service or android os should choose) – Selvin Aug 03 '11 at 18:56
  • Does it matter? At the moment I was thinking of not handling this intent myself – Greg Giacovelli Aug 03 '11 at 19:05
  • Yes ... Activity is in the same pakage you can point exaclly class of this acivity and you don't have to set type at all ... But if you wana send this intent to build in app like mms or email app you have ... Any way I saw that you already found solution :) – Selvin Aug 03 '11 at 19:17
  • No sadly my previous solution is not correct (I deleted it). SEND_MULTIPLE doesn't seem to make sense for a wide variety of applications. Also I meant it more so if I were to use the ACTION_SEND semantic what is the agreed upon way to listen for mixed type content (I know I could use the same package directly but that sort of defeats the purpose of a public intent listener for ACTION_SEND). – Greg Giacovelli Aug 04 '11 at 04:50
  • http://android.git.kernel.org/?p=platform/packages/apps/Email.git;a=blob;f=src/com/android/email/activity/MessageCompose.java;h=063e63e52b2196b169227359eae4dede0e4598ba;hb=8c23a70b9123b77511e3ed9bbe827fe0c26bb674 ... look at method initFromIntent ... or handleSendIntent method in http://android.git.kernel.org/?p=platform/packages/apps/Mms.git;a=blob_plain;f=src/com/android/mms/ui/ComposeMessageActivity.java;hb=5eb5aef7edef7b94a2de55bc930e5fcf644ea536 .... it seems that it is possible just setType to stream type don't worry about text – Selvin Aug 04 '11 at 08:49
  • You can set the type to whatever :) It's used for filters. The is when I want to send both Formatted text and an image *together* what good would just a stream be? Also I am not asking what is possible, I am asking what is the common way for this to be done. – Greg Giacovelli Aug 04 '11 at 15:20

1 Answers1

2

I don't know what you mean by 'common way' but I think you should set the type to intent.setType("image/*");.

EDIT:

How you send data with intent depends on the availability of apps that filter your particular action. Apps that handle ACTION_SEND may not handle ACTION_SEND_MULTIPLE. Clicking Share on HTC Gallery produces a list of applications that handle image, single or multiple. If you choose Mail then you can select multiple images. But if you choose Facebook or Peep then you can only select one image. This is my simple solution if you want to do the reverse of HTC Gallery, that is: user chooses image(s) first then you show him all compatible apps based on how many he selected.

// assuming uris is a list of Uri
Intent intent = null;
if (uris.size > 1){
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
} else if (uris.size() == 1) {
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));}
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, "Some message");
startActivity(Intent.createChooser(intent,"compatible apps:"));
inmyth
  • 8,880
  • 4
  • 47
  • 52
  • Yes you can but what I want to do is say multiple images and Text. Like if you are familiar with the HTC gallery application. At a certain point you can say Share. And it allows a UI which selects a bunch of images and captions for each image, and sends them as one huge transfer. I want to achieve this in an intent. Like package a large amount of images and text to be sent. What I mean by common, is what do most apps support. As all intents are is a protocol. you can document it all you want, but if no one follows it, it useless :) I'm looking at you, ACTION_SEND_MULTIPLE, when I say that – Greg Giacovelli Oct 28 '11 at 22:41