user1052143
user1052143

Reputation: 29

How to call default email application from my android application

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.

Upvotes: 2

Views: 3884

Answers (3)

vishal
vishal

Reputation: 542

try this code

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

Upvotes: 1

darkhie
darkhie

Reputation: 263

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[]{"[email protected]"}); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Some Subject"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, "Some body"); 
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Upvotes: 3

heneryville
heneryville

Reputation: 2929

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

Upvotes: 1

Related Questions