Send information to email [duplicate] - java

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 :"));
}
});

Related

How do I retrieve user email from Firebase Firestore and send it to an email intent when a button is clicked?

I'm trying to fetch user email using FirebaseAuth and open an email intent to show the email fetched automatically in the email.
I have tried to do the intent however I need help to get the email from Firebase and link it to email intent:
mFirebaseAuth = FirebaseAuth.getInstance();
emailButton = findViewById(R.id.openEmailButton);
emailButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
userInformation();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress#emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
}
});
public void userInformation(){
FirebaseUser user = mFirebaseAuth.getCurrentUser();
if (user != null) {
email = user.getEmail();
}
}
Instead of emailaddress#emailaddress.com I want the email address fetched from Firebase.
I need help to get the email from firebase
If you need add the email from the Firebase authentication to the intent, please note that you're almost there. Just add the email that you got from the FirebaseUser object in userInformation() method to your intent object. So please change the following line of code:
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress#emailaddress.com");
to
intent.putExtra(Intent.EXTRA_EMAIL, email);

Calling data from textview in android studio java [duplicate]

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
}

How to send automatically mails in intents?

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.");
...
}

no app to perform this action android email

There are plenty of people with this issue but none of their solution apply on mine, I try to change the Type from rfc822 to plaintext, open the email in my emulator and set an account, use intent action_sendto Uri.parse"mailto:", action send.
Do I need to install something in the emulator or this really work for a real phone?
send =(Button) findViewById(R.id.send_button);
send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"myemail#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "HEY");
emailIntent.putExtra(Intent.EXTRA_CC, "example#gmail.com");
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Choose an Email client :"));
} catch (ActivityNotFoundException anfe) {
Toast toast = Toast.makeText(email.this, "Sorry, no email client found", Toast.LENGTH_LONG);
toast.show();
}
}
}
);
Below code is working,
Use this code to send E-mail
publicvoid sendEmail() {
Log.i("Send email", "");
String[] TO = {""}; // Array of email address whom you want to send email
String[] CC = {""}; // Array of email address whom you want to keep in CC
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); // E-mail Addresss
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject"); // Email Subject
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here"); // your E-mail body
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
For more info
Intent Object - Action to send Email You will use ACTION_SEND action to launch an email client installed on your Android device. Following is simple syntax to create an intent with ACTION_SEND action
Intent emailIntent = new Intent(Intent.ACTION_SEND);
Intent Object - Data/Type to send Email To send an email you need to specify mailto: as URI using setData() method and data type will be to text/plain using setType() method as follows −
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
Intent Object - Extra to send Email
EXTRA_BCC
A String[] holding e-mail addresses that should be blind carbon copied.
EXTRA_CC
A String[] holding e-mail addresses that should be carbon copied.
EXTRA_EMAIL
A String[] holding e-mail addresses that should be delivered to.
EXTRA_HTML_TEXT
A constant String that is associated with the Intent, used with ACTION_SEND to supply an alternative to EXTRA_TEXT as HTML formatted text.
EXTRA_SUBJECT
A constant string holding the desired subject line of a message.
EXTRA_TEXT
A constant CharSequence that is associated with the Intent, used with ACTION_SEND to supply the literal data to be sent.
EXTRA_TITLE
A CharSequence dialog title to provide to the user when used with a ACTION_CHOOSER.

Android - getting an error “no application can perform this action” while trying to send a whatsapp message?

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);

Categories