views:

45

answers:

1

I've seen in applications a popup that prompts me what I do want to do with a text. I am prompted to choose from Send by SMS, Send by Email, Send by Bluetooth, Send by Fring etc.

How do I make such a popup, it seamed to be automatically built?
Also how do I tell what message to use?
And if needed how do I tell who the contact is? Maybe chooses the options based on the contact, (if has email, show email)

+3  A: 

This dialog is created through an Intent. Here is a little bit of source code that shows how to do this for sharing a custom text.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT,"Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Content ");
startActivity(Intent.createChooser(intent, ""));

The createChooser call on the Intent lets the OS search for every activity that has an intent filter on ACTION_SEND with type text/plain and the specified extras. All applications found for this Intent are now shown in the chooser.

You just have to find the correct type for your use case and supply the Intent with the needed data.

Editet do share text not email

Janusz
When will the contact be selected? (I already have that in a variable)
Pentium10
What contact should be selected? If you want to share to a specific contact you can't use a chooser that offers bluetooth, email or sms I think
Janusz
I want to have a list that is suitable for the passed contact (either SMS and/or Email) Is that possible? I know the contact id before.
Pentium10
I don't think that is possible because all this services listen for different intent types and need different extras put the bundle to work properly. In this case you may have to do the work yourself for the most common types of contact
Janusz
I think you mean intent.setType("text/plain")
HXCaine
Yeah you are right thanks
Janusz