This question already has answers here:
Email activity on Android
(3 answers)
Closed 5 years ago.
I am currently writing an app with a simple form that when you click submit, an e-mail is opened and the data entered into the textviews is automatically populated into the message body.
protected void sendEmail() {
EditText nameField = (EditText) findViewById(R.id.nameField);
String nameValue = nameField.getText().toString();
EditText dateField = (EditText) findViewById(R.id.dateField);
String dateValue = dateField.getText().toString();
EditText ahsField = (EditText) findViewById(R.id.ahsField);
String ahsValue = ahsField.getText().toString();
Log.i("Send email", "");
String[] TO = {""};
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, "Your subject...");
emailIntent.putExtra(Intent.EXTRA_TEXT, "MESSAGE BODY HERE?");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(DDActivity.this, "There is no email client installed", Toast.LENGTH_SHORT).show();
}
}
This is what i have so far, any help would be greatly appreciated!
The following code works just tried it
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"foo#bar.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Choose email...");
} catch (android.content.ActivityNotFoundException ex) {
// handle edge case where no email client is installed
}
Related
//Intent to gmail
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setData(Uri.parse("mailto:"));
//how can ı add this part
sendIntent.putExtra(Intent.EXTRA_EMAIL,fromEmail);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
sendIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
sendIntent.setType("text/plain");
try {
Intent shareIntent = Intent.createChooser(sendIntent, "Feedback");
startActivity(shareIntent);
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
The sender works fine, but I couldn't make the receiver. Can you help me?
I don't know exactly how the design is. I'm also not sure where you got the recipient email from, but maybe this code will be useful for you.
public void contact() {
final Intent send = new Intent(Intent.ACTION_SENDTO);
final String email = "youremail#gmail.com";
final String subject = "subject";
final String body = "body...";
final String uriText = "mailto:" + Uri.encode(email) +
"?subject=" + Uri.encode(subject) +
"&body=" + Uri.encode(body);
final Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, getString(R.string.settings_email_chooser)));
}
I`m trying to send an email to multiple people without opening the chooser is that possible?
I tried to use a array but it gave me an error.
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("example#gmail.com") +
"?subject=" + Uri.encode("the subject") +
"&body=" + Uri.encode("the body of the message");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send Email..."))
Correct way to send email to multiple user is:
Kotlin:
private fun emailToMultipleUser() {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.setPackage("com.google.android.gm")
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("example#gmail.com","chand#gmail.com"))
intent.putExtra(Intent.EXTRA_SUBJECT, "email subject")
intent.putExtra(Intent.EXTRA_TEXT, "Hi All ...")
try {
startActivity(Intent.createChooser(intent, "send mail"))
} catch (ex: ActivityNotFoundException) {
Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT)
} catch (ex: Exception) {
Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT)
}
}
Java:
private void emailToMultipleUser() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType( "text/plain");
intent.setPackage("com.google.android.gm");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"example#gmail.com","chand#gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "email subject");
intent.putExtra(Intent.EXTRA_TEXT, "Hi All ...");
try {
startActivity(Intent.createChooser(intent, "send mail"));
} catch (ActivityNotFoundException ex) {
Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT);
} catch (Exception ex) {
Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT);
}
}
This is some code I have:
public void sendIt(View view){
EditText editText = (EditText) findViewById(R.id.editText);
String string = editText.getText().toString();
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, "mymail#domain.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "This is the subject.");
intent.putExtra(Intent.EXTRA_TEXT, "This is extra text.");
...
}
I want that if this method is called it opens an E-mailapp and a mail with as subject: "This is the subject." and as text: "This is the extra text." That does the app so that's correct.
But I want too that automatically the field "Send to" cointains mymail#domain.com. That doesn't my app. How to do that?
What may be other fine is that it too automatically sends the mail.
Use this line to add EXTRA_EMAIL :
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"mymail#domain.com"});
It works fine for me. Try and notify whether it helps or not.
Try like this
public void sendIt(View view){
EditText editText = (EditText) findViewById(R.id.editText);
String string = editText.getText().toString();
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "mymail#domain.com" });
intent.putExtra(Intent.EXTRA_SUBJECT, "This is the subject.");
intent.putExtra(Intent.EXTRA_TEXT, "This is extra text.");
...
}
This question already has answers here:
How to send emails from my Android application?
(26 answers)
Closed 7 years ago.
I have an activity, which has two TextFields, where the user can input some text.
There is a button below them, which I want to submit the information input the two TextFields. Either as an email or a message.
Is there a way where the activity is basically submitting the user info to me?
You need to use an Intent to open "Compose new email" with required data filled in.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{emailAddressEditText.getText().toString()});
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubjectEditText.getText().toString());
intent.putExtra(Intent.EXTRA_TEXT , emailBodyEditText.getText().toString());
try {
startActivity(Intent.createChooser(intent, "Leave feedback..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "No email clients installed.", Toast.LENGTH_SHORT).show();
}
1.Use Intent
2.Use .setType("message/rfc822")
buttonSend = (Button) findViewById(R.id.buttonSend);
textTo = (EditText) findViewById(R.id.editTextTo);
textSubject = (EditText) findViewById(R.id.editTextSubject);
textMessage = (EditText) findViewById(R.id.editTextMessage);
buttonSend.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String to = textTo.getText().toString();
String subject = textSubject.getText().toString();
String message = textMessage.getText().toString();
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");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
});
I am practising by making an app in which the user can send a WhatsApp message to a particular person .I tried some code snippets which i found on internet but whenever i try to send a WhatsApp msg from an actual device, i am gettig an error "No Application can perform this action".
Here is my code:-
public void sendMessage(View v) {
try
{
String whatsAppMessage = message.getText().toString();
Uri uri = Uri.parse("smsto:" + "9888873438");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
i.setType("text/plain");
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
}catch (Exception e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
}
Please help .
You receive no application can perform this action because you should remove i.setType("text/plain"); from your code:
String whatsAppMessage = message.getText().toString();
Uri uri = Uri.parse("smsto:" + "9888873438");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
Unfortunately as you can see WhatsApp now opens in the conversation activity but there isn't the text you set in the Intent. This is because WhatsApp doesn't support this kind of share. The only supported share with Intent is ACTION_SEND as you can see in the WhatsApp FAQ:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);