In my android application having one button to send mail, When I click that send button using startActivity(Intent.createChooser(emailIntent, "Send Mail...")); this line Gmail will open and then I click send mail. Mail will sent successfully at the same time my application get closed why ? I need to stay in that same page ?
try
{
String extpath=Environment.getExternalStorageDirectory() +"/NewFolder/DBName";
File pathp=new File(extpath);
Log.d("New Path", pathp.toString());
long fileSize = pathp.length();
if(fileSize > 0)
{
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String address = "mailid#yourmail.com";
String subject = "Database";
String emailtext = "Please check the attached database and save it";
emailIntent.setType("application/octet-stream");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + pathp));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext);
startActivity(Intent.createChooser(emailIntent, "Send Mail..."));
}
else
{
Log.d("Error", "Attachment didn't attach ");
}
}
catch (Throwable t)
{
Log.d("Error on sending mail", t.toString());
}
When i run this code mail sent and then application will get close. I don't want to close application. Help me thanks in advance.
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
Button button;
Session session;
ProgressDialog dialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
SendMailBySite bySite=new SendMailBySite();
bySite.execute();
}
class SendMailBySite extends AsyncTask<Void, Void, Void>{
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog=new ProgressDialog(MainActivity.this);
dialog.setMessage("Sending mail.....");
dialog.show();
}
#Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
final String user="XXXXXXXX#gmail.com";//change accordingly
final String password="XXXXXXX";//change accordingly
String to="toXXXXXXXX#gmail.com";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,password);
}
});
//Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Mobiappsdevelper");
message.setText("This is simple program of sending email using JavaMail API");
//send the message
Transport.send(message);
} catch (MessagingException e) {e.printStackTrace();}
return null;
}
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
dialog.dismiss();
Toast.makeText(getApplicationContext(), "message sent successfully...", 3000).show();
}
}
}
You Can Use This Code:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Related
I want to send images via email in my android app. For which I'm using Android Native Camera app and Intents to use the respective service. I've used the following code:
Email is getting send but if I'm trying to add image the app gets crash.
public class Complaints extends AppCompatActivity {
Button sendEmail;
EditText to, subject, msg;
Bitmap image;
Button camera;
File pic;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_complaints);
to = (EditText) findViewById(R.id.et1);
subject = (EditText) findViewById(R.id.et2);
msg = (EditText) findViewById(R.id.et3);
sendEmail = (Button) findViewById(R.id.s_Email);
camera = (Button) findViewById(R.id.btn_img);
camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(intent,"Select Picture"));
}
});
sendEmail.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String Emailid = to.getText().toString();
String sub = subject.getText().toString();
String message = msg.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{Emailid});
email.putExtra(Intent.EXTRA_SUBJECT, sub);
email.putExtra(Intent.EXTRA_TEXT, message);
email.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//this will make such that when user returns to your app, your app is displayed, instead of the email app.
email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
email.setType("message/rfc822");
email.setType("image/jpeg");
try {
startActivity(Intent.createChooser(email, "Message was Sent"));
}
catch (ActivityNotFoundException e) {
Toast t = Toast.makeText(Complaints.this, "There is No Emial Client installed ", Toast.LENGTH_SHORT);
t.setGravity(Gravity.CENTER, 0, 10);
t.show();
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 10) {
image = (Bitmap) data.getExtras().get("Data");
ImageView i = (ImageView) findViewById(R.id.img);
i.setImageBitmap(image);
try
{
File root= Environment.getExternalStorageDirectory();
if(root.canWrite())
{
pic=new File(root,"pic.jpeg");
FileOutputStream out=new FileOutputStream(pic);
image.compress(Bitmap.CompressFormat.JPEG,100,out);
out.flush();
out.close();
}
} catch (IOException e)
{
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
}
}
}
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.net.Uri;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.Media;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class Complaints extends Activity {
Button send;
Bitmap thumbnail;
File pic;
EditText address, subject, emailtext;
protected static final int CAMERA_PIC_REQUEST = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_complaints);
send=(Button) findViewById(R.id.emailsendbutton);
address=(EditText) findViewById(R.id.emailaddress);
subject=(EditText) findViewById(R.id.emailsubject);
emailtext=(EditText) findViewById(R.id.emailtext);
Button camera = (Button) findViewById(R.id.button1);
camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
});
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0){
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"dummy#email.com"});
i.putExtra(Intent.EXTRA_SUBJECT,"dummy subject");
//Log.d("URI#!##!#!###!", Uri.fromFile(pic).toString() + " " + pic.exists());
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
i.setType("image/png");
startActivity(Intent.createChooser(i,"Share this"));
}
});
}
Getting The Image Path and converting path into Uri :
File photo = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/Fault", imagename+".png")
Uri imageuri = Uri.fromFile(photo);
Sending through Email Intent :
Intent send_report = new Intent(Intent.ACTION_SEND);
send_report.putExtra(Intent.EXTRA_EMAIL, new String[]{ email_emailid});
send_report.putExtra(Intent.EXTRA_SUBJECT, email_subject);
send_report.putExtra(Intent.EXTRA_STREAM, imageuri);
send_report.putExtra(Intent.EXTRA_TEXT, email_body);
send_report.setType("text/plain");
send_report.setType("image/png");
startActivityForResult(Intent.createChooser(send_report, "Choose an Email client"), 77);
Here is my code that is able to sent email successfully
package com.send.email;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
Button send;
EditText address, subject, emailtext;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send = (Button) findViewById(R.id.emailsendbutton);
address = (EditText) findViewById(R.id.emailaddress);
subject = (EditText) findViewById(R.id.emailsubject);
emailtext = (EditText) findViewById(R.id.emailtext);
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address.getText().toString() });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
MainActivity.this.startActivity(Intent.createChooser(emailIntent,"Send mail..."));
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode==1)
{
if(requestCode==1 && resultCode==Activity.RESULT_OK)
{
Toast.makeText(this, "Mail sent.", Toast.LENGTH_SHORT).show();
}
else if (requestCode==1 && resultCode==Activity.RESULT_CANCELED)
{
Toast.makeText(this, "Mail canceled.", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, "Plz try again.", Toast.LENGTH_SHORT).show();
}
}
}
}
I want to get some information back to check whether the email has been sent successfully or not. It always prints the message "send email" and opens built-in email client and sends email.
You cannot do this using : android.content.Intent.ACTION_SEND.
Just try to send a mail using the mailing app to a email ID that doesnot exist. You will see that the app does not notify you of the failed delivery. Using android.content.Intent.ACTION_SEND, you are actually passing an intent to the same app to do the email delivery task for you. So you will never know if your mail delivery has failed.
The work around.
You need to implement the email delivery a 3rd party Library mail.jar or some thing similar. But the thing is you need to have senders' mailID and PASSWORD both to set this up. May be you can have a dummy email account with which you can send the mail.
This can help.
I have tried to send image by attachment in email intent.
I select gmail app, it seems file is attached, but when i click on send on gmail app it says:
Unfortunately, Gmail has stopped.
Please help me what is the problem and how can i fix it?
AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
MyActivity.java:
public class MyActivity extends Activity {
private static final int SELECT_PICTURE = 1;
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 2;
private String selectedImagePath;
TextView uritv=null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
uritv = (TextView) findViewById(R.id.uritxt);
Button send = (Button) findViewById(R.id.sendBtn);
send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (uritv.getText().toString().equals("URI")) {
Toast.makeText(getApplicationContext(),"Please choose an image first!",Toast.LENGTH_SHORT).show();
} else {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"myemail#myemail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(uritv.getText().toString()));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
}
});
Button galbtn = (Button) findViewById(R.id.galBtn);
galbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});
Button cambtn = (Button) findViewById(R.id.camBtn);
cambtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE || requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
uritv.setText(selectedImagePath.toString());
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
}
It requires Internet permissions, add this permission in manifest file
<uses-permission android:name="android.permission.INTERNET"/>
yes the problem is with the URI you build to get the file path. you are taking the raw file path which is not the case with the URI. it should be like below
content://media/external/images/media
Please check your path and test that again
I done some alteration and i can send the Mail successfully.. Since you are using Gmail use a GmailSender Class. Like this
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.Security;
import java.util.List;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import android.net.Uri;
public class GMailSender extends javax.mail.Authenticator {
private String mailhost = "smtp.gmail.com";
private String user;
private String password;
private Session session;
String ContentType = "";
static {
Security.addProvider(new JSSEProvider());
}
public GMailSender(String user, String password) {
this.user = user;
this.password = password;
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", mailhost);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
session = Session.getDefaultInstance(props, this);
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
public synchronized void sendMail(String subject, String body,
String sender, String recipients, List<Uri> uriList)
throws Exception {
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
recipients));
message.setSubject(subject);
// 3) create MimeBodyPart object and set your message content
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setText(body);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart1);
for (int i = 0; i < uriList.size(); i++) {
// 4) create new MimeBodyPart object and set DataHandler object
// to this object
MimeBodyPart messageBodyPart2 = new MimeBodyPart();
String filename = uriList
.get(i)
.getPath()
.substring(
uriList.get(i).getPath().lastIndexOf("/") + 1,
uriList.get(i).getPath().length());// change
// accordingly
System.out.println("filename " + filename);
DataSource source = new FileDataSource(uriList.get(i).getPath());
messageBodyPart2.setDataHandler(new DataHandler(source));
messageBodyPart2.setFileName(filename);
// 5) create Multipart object and add MimeBodyPart objects to
// this object
multipart.addBodyPart(messageBodyPart2);
}
// 6) set the multiplart object to the message object
message.setContent(multipart);
// 7) send message
Transport.send(message);
System.out.println("message sent....");
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
}
And it is always best to keep your mail sending in a Async Task or Thread. And call this in your send Button.
class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
private ProgressDialog progressDialogue;
private Boolean status = false;
#Override
protected Boolean doInBackground(Void... arg0) {
try {
ArrayList<Uri> uList = new ArrayList<Uri>();
u.add(Uri.parse(uritv.getText().toString()));
try {
GMailSender sender = new GMailSender("<Sender Mail>",
"<Sender Password>");
Log.d("TAG: ", "Mail SENT");
sender.sendMail("Subject Text", "Body Text", "<Sender Mail>", "<Recipient Mail>", uList);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return status;
} catch (Exception e) {
e.printStackTrace();
return Boolean.FALSE;
}
}
protected void onPreExecute() {
progressDialogue = ProgressDialog.show(MainActivity.this,
"Sending Mail...",
"Please Wait..", true,
false);
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(Boolean result) {
// result is the value returned from doInBackground
progressDialogue.dismiss();
}
}
i have made an activity
at subscribe button, i have to send email to some default email for which my code is:
package sditm.app;
import android.R.string;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class subscribeActivity extends Activity {
/** Called when the activity is first created. */
EditText name,age,address;
databaseforsubscribe addressBook;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subscribe);
Button store = (Button)findViewById(R.id.button1);
name=(EditText)findViewById(R.id.editText1);
age=(EditText)findViewById(R.id.editText2);
address=(EditText)findViewById(R.id.editText3);
addressBook = new databaseforsubscribe(this,"addressDB",null,2);
store.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String s=new String();
String m=new String();
String n=new String();
s=name.getText().toString();
m=age.getText().toString();
n=address.getText().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, "aman4251#gmail.com");
// i.putExtra(Intent.EXTRA_EMAIL , new String[]{"aman4251#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT ,"NAME: "+s+" ; MOBILE: "+m+" ; EMAIL: "+n);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(subscribeActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
which open an intent like this
now either i have to set the email id to "To" textbox (and make it uneditable"), or to automatically click on that "send" button so that user dont see this intent and email is send in back ground..
Try this code:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.",Toast.LENGTH_SHORT).show();
}
Hi try this piece of code
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Add attributes to the intent
sendIntent.putExtra(Intent.EXTRA_EMAIL, "");
sendIntent.putExtra(Intent.EXTRA_CC, "");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
sendIntent.putExtra(Intent.EXTRA_TEXT, "");
sendIntent.setType("text/plain");
PackageManager pm = getPackageManager();
List<ResolveInfo> activityList = pm
.queryIntentActivities(sendIntent, 0);
Iterator<ResolveInfo> it = activityList.iterator();
boolean isEmailSetUp = false;
while (it.hasNext()) {
ResolveInfo info = it.next();
if ("com.android.email.activity.MessageCompose"
.equalsIgnoreCase(info.activityInfo.name)) {
isEmailSetUp = true;
sendIntent.setClassName(info.activityInfo.packageName,
info.activityInfo.name);
}
}
if (isEmailSetUp) {
startActivity(sendIntent);
} else {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("No Mail Accounts");
dlgAlert.setTitle("Please set up a Mail account in order to send email");
dlgAlert.setPositiveButton(getResources().getString(R.string.ok),
null);
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
i dono know whether it is possible to make the email id edit text uneditable
But you can send mail in background by click on button
for that refer this link
I have tried this till now
register.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
Username = username.getText().toString();
Email = email.getText().toString();
System.out.println("clicked register Button");
System.out.println(" User name is :" + Username );
System.out.println(" Email Id is :" + Email);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , Email);
i.putExtra(Intent.EXTRA_EMAIL , Email);
i.putExtra(Intent.EXTRA_SUBJECT, "You are registered for Aero india");
i.putExtra(Intent.EXTRA_TEXT , "Get the print out of this email while coming to the venue");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
ex.printStackTrace();
}
}
});
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* Class which shows how to send email
*
* #author FaYna Soft Labs
*/
public class Main extends Activity {
private Button clickBtn;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
clickBtn = (Button) findViewById(R.id.click);
clickBtn.setText("Send email");
clickBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String[] recipients = new String[]{"my#email.com", "",};
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email's message");
emailIntent.setType("text/plain");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
}
});
}
}