RSS

Android Creating an Email Intent

26 Jun

Today I checked out about the android email Intent. Built a pretty simple app that doesn’t do much but passes on some info to the default email application in the phone. Btw guys I am sorry about the format of the code. I also have to mention: I dont know why but you cant send email through your emulator with this app, It only works on a real phone

.


//Code starts here

package com.learning.gilo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SendEmail extends Activity implements View.OnClickListener{

Button send;
EditText email, message,subj;

protected void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.email);
send = (Button) findViewById(R.id.bSend);
email = (EditText) findViewById(R.id.etEmail);
message = (EditText) findViewById(R.id.etBody);
subj = (EditText) findViewById(R.id.etSubject);

send.setOnClickListener(this);

}

public void onClick(View v) {
String emailaddress = email.getText().toString();
String[] address = {emailaddress};

String body = message.getText().toString();

String subject = subj.getText().toString();

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); //This is the email intent
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, address); // adds the address to the intent
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);//the subject

emailIntent.setType("plain/text");

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body); //adds the body of the mail

startActivity(emailIntent);

}
}

Advertisements
 
5 Comments

Posted by on June 26, 2012 in Android, Android tutorials

 

5 responses to “Android Creating an Email Intent

  1. techinnovate

    October 17, 2012 at 9:36 am

    Hi, is there anyway I can activate/enable the SEND button of this mail intent programatically without user interaction?? OR can I enable tts on this intent?

     
  2. Gilbert Kimutai

    October 17, 2012 at 10:11 am

    I am not getting you clearly, but if you want the app to send mail on its own maybe after a period of time (periodically) or at a certain time, then you could try creating a Service – they ran on the background. Even though still the user will be notified to choose an app to send the mail through.

     
    • techinnovate

      October 18, 2012 at 2:43 am

      thanks, will check that out

       
      • techinnovate

        October 18, 2012 at 2:45 am

        The constraint is, I do not want the user to enter the password…

         

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: