Email, Send, Intent, IntentChooser

Quickly share your Android Code Snippets here...

Email, Send, Intent, IntentChooser

Postby plusminus » Mon Oct 27, 2008 5:44 am

Short snippet to start an Email-Activity with some preset data:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
  2.  
  3. emailIntent .setType("plain/text");
  4.  
  5. emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"webmaster@website.com"});
  6.  
  7. emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, mySubject);
  8.  
  9. emailIntent .putExtra(android.content.Intent.EXTRA_TEXT, myBodyText);
  10.  
  11. context.startActivity(Intent.createChooser(intent, "Send mail...));
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby snappy » Thu Dec 11, 2008 10:36 pm

Thank you so much for this.

Is there a way to use the "share" intent which is used in the camera application or the picture viewer app so you can send by E-Mail or SMS and bundle the data depending on what is selected?
snappy
Freshman
Freshman
 
Posts: 5
Joined: Thu Dec 11, 2008 9:29 pm

Postby snappy » Fri Dec 12, 2008 7:12 am

Has anyone got this working?

I tried:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
  2.  
  3.                 emailIntent.setType("plain/text");
  4.  
  5.                 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"webmaster@website.com"});
  6.  
  7.                 emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "mySubject");
  8.  
  9.                 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "myBodyText");
  10.  
  11.                 startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


I get "No applications can perform this action." It seems a lot of people have been getting this. I've tried a lot of things but I cannot seem to get the email application to start unless I set the type to "image/jpeg" but it still won't set the email/subject/body.
snappy
Freshman
Freshman
 
Posts: 5
Joined: Thu Dec 11, 2008 9:29 pm

Postby Rahul » Fri Dec 12, 2008 1:15 pm

I think that code would work only in a real Android device.

http://groups.google.com/group/android- ... c676e3217b
Rahul
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Wed Oct 01, 2008 11:16 am

Postby snappy » Fri Dec 12, 2008 5:32 pm

Rahul wrote:I think that code would work only in a real Android device.

http://groups.google.com/group/android- ... c676e3217b


Yep. Took me awhile to figure that out, but I checked the email client source and it only allows intents to
be called with image attachments. I don't think it even recognizes the EXTRA_SUBJECT/EXTRA_BODY/etc.
fields.

It seems the email app is extremely premature.

But to be fair, it wouldn't take much to fix up the email apps source to respond to intents and unbundle the email/subject/body.
snappy
Freshman
Freshman
 
Posts: 5
Joined: Thu Dec 11, 2008 9:29 pm

Postby plusminus » Sun Dec 14, 2008 7:35 am

Yes, it works on real devices ! (Didn't include the last SDK-Update the email-client for the emulator ??)

Best Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby FenianEMT » Tue Dec 23, 2008 11:33 pm

Just tried this on a G1 and it works great. Just one question:

Is there any way to send an email without requiring user input? I'm looking for something along the lines of the SmsManager's sendTextMessage() method, but for email.
FenianEMT
Freshman
Freshman
 
Posts: 8
Joined: Tue Dec 23, 2008 11:31 pm

Postby llanero » Thu Apr 02, 2009 11:33 am

Hi,
I'm new here. Thanks a lot for this email activity. I've included it in my new android app, that will be born nearly, I hope. The email works perfectly now from my app in the G1.
But I've a question: How can I do to send an e-mail with a file attached?
llanero solitario
llanero
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 02, 2009 10:45 am

Postby alpesh_harsoda » Fri May 01, 2009 2:26 pm

Hi, i have also same ques. how can i attach txt or image file to attach in my mail? :)
Regards,
Alpesh Patel,
Logistic Infotech
http://www.logisticinfotech.com
User avatar
alpesh_harsoda
Senior Developer
Senior Developer
 
Posts: 106
Joined: Sat Sep 20, 2008 12:35 pm
Location: Rajkot,Gujarat(India)

emailIntent.setType("html/text");

Postby sikus » Thu May 07, 2009 2:50 pm

Hello, I need send email like html. I try use emailIntent.setType("html/text"); but text in email is with tags, not like html page. Haw can I do it? Thanks for recommend.
sikus
Junior Developer
Junior Developer
 
Posts: 12
Joined: Mon Dec 15, 2008 3:48 pm

Postby twsc » Sat May 09, 2009 2:39 pm

alpesh_harsoda wrote:Hi, i have also same ques. how can i attach txt or image file to attach in my mail? :)


you can refer this article. it can attach the image file.
send_the_picture_via_gmails_attached_function-t4586.html


If you want to attach the txt file, you may check this.
http://developer.android.com/reference/ ... CTION_SEND

"text/plain";
twsc
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Jan 28, 2009 2:23 pm

Postby alpesh_harsoda » Sat May 09, 2009 2:48 pm

Thnks for Help.
Regards,
Alpesh Patel,
Logistic Infotech
http://www.logisticinfotech.com
User avatar
alpesh_harsoda
Senior Developer
Senior Developer
 
Posts: 106
Joined: Sat Sep 20, 2008 12:35 pm
Location: Rajkot,Gujarat(India)

Postby bhushan.kasturiwale » Wed May 27, 2009 10:31 am

Hello ,

Can we start the IM (chat) application similarly as we have don for the Email application.
I need start the IM (chat) application from my application can any one help me out with it.

Thanks!
Bhushan
bhushan.kasturiwale
Freshman
Freshman
 
Posts: 4
Joined: Mon May 25, 2009 12:35 pm

Postby SlumberMachine » Wed May 27, 2009 7:10 pm

bhushan.kasturiwale wrote:Hello ,

Can we start the IM (chat) application similarly as we have don for the Email application.
I need start the IM (chat) application from my application can any one help me out with it.

Thanks!
Bhushan


Yes! you can create an intent to open a messenger program. Any app can receieve intents if the creator of the app included intent receivers.

For chat, The most important thing to change is the "type" field to the appropriate type for the receiving app. Also, you need to make sure you have your IM application installed and working correctly before attempting to send the intent, otherwise it will not find it.
SlumberMachine
Developer
Developer
 
Posts: 39
Joined: Tue Feb 24, 2009 9:00 pm

Postby SlumberMachine » Wed May 27, 2009 7:11 pm

I cannot seem to get the email address, cc, or bcc fields to populate the strings I'm sending them. Anyone know why this is? I am using the same code as the original in this thread.
SlumberMachine
Developer
Developer
 
Posts: 39
Joined: Tue Feb 24, 2009 9:00 pm

Top
Next

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 7 guests