Monday, March 7, 2011

Android Intents How to send an email from an Android application?

By Magesh Kumar   Posted at  4:34 AM   Android No comments


Here are two methods using intents.
Method one, you want to let the user choose the email client:
Button sendBtn = (Button) findViewById(R.id.send_btn_id);
sendBtn.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v){
  Intent i = new Intent(Intent.ACTION_SEND); 
  //i.setType("text/plain"); //use this line for testing in the emulator 
  i.setType("message/rfc822") ; // use from live device
  i.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@gmail.com"}); 
  i.putExtra(Intent.EXTRA_SUBJECT,"subject goes here"); 
  i.putExtra(Intent.EXTRA_TEXT,"body goes here"); 
  startActivity(Intent.createChooser(i, "Select email application."));
  }
});
and method two, you want to specify a client (NoteToMe here), replace the intent request by:
NoteToMe.this.startActivity(emailIntent);
NoteToMe.this.finish();


About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments:

Back to top ↑
Connect with Us

What they says

© 2013 MaGeSH 2 help. WP Mythemeshop Converted by BloggerTheme9
Blogger templates. Proudly Powered by Blogger.