Recipients are not showing in email screen in Android - android

Hi I am using in built email sending functionality.But when I tried the code.
void sendEmailMessage(String emailId)
{
Log.i(TAG, "emailId = "+emailId);
Intent intentEmail = new Intent(Intent.ACTION_SEND);
intentEmail.setType("text/plain");
String[] recipients = new String[]{emailId};
intentEmail.putExtra(Intent.EXTRA_EMAIL,recipients);
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intentEmail.putExtra(Intent.EXTRA_TEXT, "body of email");
try
{
startActivity(Intent.createChooser(intentEmail, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
ex.printStackTrace();
}
}
I don't see recipient email address in recipient EditText on Email screen.I am not getting what I am doing wrong please help.

I think in your void sendEmailMessage(String emailId) method's emailId argument didn't have the value. Just check where you've been called from. And, make sure you are passing email id or not? For example. In your class's somewhere just call that method like below with value.
sendEmailMessage("mail#mail.com");

Related

How do i get information typed on editText?

So I have an editText in an app I created, the aim of this editText is to send a piece of text information. I want the user to be able to send text information for me to use, it's kinda like when you have a "FeedBack" option and the user has to fill it with the required information needed, I want to be able to get this information somehow. Pls help, I'm still new to the mobile app development thing. :)
Use getText() on your EditText. This will return an Editable which can be casted to String if you want:
String feedback = editTextFeedback.getText().toString();
If you want to receive the input by mail:
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();
}
What you can do is opening a "share" activity and send the text through any app you have in the phone (whatsapp, telegram, mail, etc).
public void share(message: String) {
try {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Sending message");
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
Intent.createChooser(shareIntent, "Share with");
} catch (Exception e) {
e.printStackTrace()
}
}
This will open a window like this:

How can I tell if my email has been sent?

I'm using the following code to send an email in my app.
public void sendEmail() {
emailSent = 1;
String to = toEmail.getText().toString();
String subject = getUser() + " - User Feedback";
String message = bodyTxt;
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
email.setType("message/rfc822");
try {
startActivity(Intent.createChooser(email, "Send Email..."));
} catch (android.content.ActivityNotFoundException ex) {
String msg = ex.getMessage().toString();
emailSent = 2;
Toast.makeText(this, "There was a problem sending this email, please try again.", Toast.LENGTH_SHORT).show();
}
}
The email.setType() presents a screen offering options for which method to send the message including email. This works fine if the user selects email as a copy of the email comes up and the user can then send it. However, if the user doesn't do anything and simply uses the back space it returns to the app and assumes the email has been sent. How can I test for the user not sending the email?
You could startActivityForResult() and listen for a RESULT_OK in onActivityResults. But there is no framework requirement that forces the email app to setResult appropriately. So your mileage may vary based on the email client app.

Android: Email 'to ' field empty

I am developing an application for a hotel, where in, on booking a room, the app sends an email to the email-id given by the user. Now, i know it will use one of my default email clients, which is the gmail. The problem is, it is showing up with gmail's compose message window, with my message in the message body,but the 'to'field is empty. Any help?
here is the code:
public void sendmail(View vw)
{
name=et1.getText().toString();
to=et2.getText().toString();
phone=et3.getText().toString();
addr=et4.getText().toString();
Log.i("Send email", "");
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Thanks for using our app");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Hello mr"+name+"We just received an email with your details asking for a reservation:"+phone+" "+addr+"for room number"+x+"");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getBaseContext(), "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
}
From the documentation of EXTRA_EMAIL:
A String[] holding e-mail addresses that should be delivered to.
Something like this should work:
Intent mailIntent = new Intent(Intent.ACTION_SENDTO);
mailIntent.setData(Uri.parse("mailto:"));
mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
mailIntent.putExtra(Intent.EXTRA_SUBJECT, "Thanks for using our app");
mailIntent.putExtra(Intent.EXTRA_TEXT, "Hello mr"+name+"We just received an email with your details asking for a reservation:"+phone+" "+addr+"for room number"+x+"");
if (mailIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mailIntent);
} else {
// no e-mail app installed
}
Try this :
emailIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#to.com"});
email intent expects an String array but you're providing a string.So, it's not working in your case!

email sending by android.content.Intent.ACTION_SEND do not display email picker:

I notice if I use the below code to sedn email, email compse is shown. however, I can't pick email from contact, rather I have to fill up email address. Is there aay to let user pick up an email address from contact:
public void sendSimpleEmail(View button) {
try {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
startActivity(emailIntent);
} catch (Exception e) {
Log.e(LOG_TAG, "sendSimpleEmail() failed to start activity.", e);
Toast.makeText(this, "No handler", Toast.LENGTH_LONG).show();
}
}
replace your startActivity(emailIntent); with startActivity(Intent.createChooser(emailIntent));
As "nandeesh" answered above, it depends on the email application, some may allow some may not . In my case i was trying with simulator only.

Add data from activity to email message body

I feel dumb for having to ask this but I cannot find how to take UI information from multiple EditText views and place in an email body. FYI I have the intent down, I just want to populate the message body.
Intent buildingfireemail = new Intent(android.content.Intent.ACTION_SEND);
buildingfireemail.setType("plain/text");///.setType("message/rfc822")
buildingfireemail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to#email.com"});
buildingfireemail.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
buildingfireemail.putExtra(android.content.Intent.EXTRA_TEXT, "Text"
//////////////I need to add data from 80+ views into here.
);try {
startActivity(Intent.createChooser(buildingfireemail, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(BuildingFireActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Try this :
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 , editText.getText().toString());
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();
}
Create a function which returns the whole String from all your text edits. For example:
private String getText() {
String text = "";
text += mEditText1.getText().toString() + "\n";
text += mEditText2.getText().toString() + "\n";
return text;
}
Use like:
buildingfireemail.putExtra(android.content.Intent.EXTRA_TEXT, getText());
Init member variables for class:
private EditText mEditText1;
Take all edit texts to member variables in onCreate after setContentView:
mEditText1 = (EditText) findViewById(R.layout.editText1);

Categories

Resources