Saturday, September 8, 2012

Email Intent Demo In Android

This example will show you how to open email composer through your application.
1.) Create a new project by File-> New -> Android Project name it EmailIntentDemo.
2.) You will see some default code into your main.xml, strings.xml and android manifest file.
3.) Now add 1 buttons into your main.xml or write following into main.xml file:
<LinearLayout xmlns:android=""
   android:layout_height="fill_parent" >
        <Button android:text="Share" android:id="@+id/button1"

4.) Your launcher activity EmailIntentDemo will have one default functions OnCreate().
5.) You must have to configure any email onto your device or simulator to get the output on this demo.
6.) To configure email goto applications and select “Email”, now follow the instructions given and configure your email onto device or simulator.
1.) Create a project named EmailIntentDemo and set the information as stated in the image.
Build Target: Android 1.6
Application Name: EmailIntentDemo
Package Name: com.example. EmailIntentDemo
Activity Name: EmailIntentDemo
Min SDK Version: 4
2.) Open file and write following code there:
package com.example.EmailIntentDemo;
import java.util.List;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class EmailIntentDemo extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        Button shareButton = (Button) findViewById(;
        shareButton.setOnClickListener(new OnClickListener() {
                public void onClick(View arg0) {
                        Intent emailIntent = newIntent(android.content.Intent.ACTION_SEND);
                        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Email Intent Example");
                        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"This is email is generated using EmailIntent Demo application to sow how we can directly compose a mail from our application.");
                        final PackageManager pm = getPackageManager();  
                        final List<ResolveInfo> matches =pm.queryIntentActivities(emailIntent, pm.MATCH_DEFAULT_ONLY);  
                        ResolveInfo best = null;  
                        for (final ResolveInfo info : matches)
                                        best = info;
                        if (best != null)
3.) Compile and build the project.
4.) Run on 1.6 simulator for the output.

No comments:

Post a Comment