2

I am new to Android application development and with very little java knowledge. I want to call the default Android email application from my application once a button is clicked. What code should i use ?

Thanks And Regards.

Shihab Uddin
  • 6,699
  • 2
  • 59
  • 74
user1052143
  • 29
  • 1
  • 2
  • 3
    The answer is in the *Related* bar on the right, took me 20 seconds to spot it. Please do a little research before you ask next time. Thanks. –  Nov 17 '11 at 15:54
  • see http://stackoverflow.com/questions/3470042/intent-uri-to-launch-gmail-app – Marc Van Daele Nov 17 '11 at 15:54
  • 1
    It takes 10x more time to ask that question and wait for the possible answer than to use the search bar. You can already see those that are here for the reputation alone doing a disservice to the board. – davidcesarino Nov 17 '11 at 15:57
  • i tried that before but it link me to the gmail application. i need to call the default email application which is email.apk. Thanks – user1052143 Nov 18 '11 at 02:06

3 Answers3

3

You can create an email intent for that:

final Intent emailIntent = new Intent(Intent.ACTION_SEND); 
emailIntent.setType("text/plain"); 
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"address@domain.com"}); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Some Subject"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, "Some body"); 
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
darkhie
  • 263
  • 1
  • 15
  • i just need to launch the email application. which is something like this. Intent mailClient = new Intent(Intent.ACTION_VIEW); mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity"); startActivity(mailClient); – user1052143 Nov 18 '11 at 02:12
1

try this code

Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("plain/text");
sendIntent.setData(Uri.parse("demoemail@gmail.com"));
sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "demoemail@gmail.com" });
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "demo of email");
sendIntent.putExtra(Intent.EXTRA_TEXT, "hi my message");
startActivity(sendIntent);
vishal
  • 542
  • 6
  • 12
1

In Android, you launch other activities by sending an intent to the android OS. The OS will then determine what activities subscribe to the intent, and either use a default or allow the user to select one. Use the following intent to just launch email:

Intent email = new Intent(android.content.Intent.ACTION_SEND)

You can also include a default subject, to field, content, etc by using the bundle on the intent. There is a great tutorial here

heneryville
  • 2,853
  • 1
  • 23
  • 30