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.");
...
}
Related
I have a problem that I want in my application to have a specific email receiver whenever the user press the email button it shows to him/her a fixed receiver. How can I do this?
public void google(View v){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
Intent shareIntent = Intent.createChooser(emailIntent,"");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shareIntent);
}
this is the code
this is the image of email
Use this code hope it will help
Intent Email = new Intent(Intent.ACTION_SEND);
String[] recipents ={"your_recepient_email"};
Email.putExtra(Intent.EXTRA_EMAIL,recipents);
Email.setType("text/html")
Email.setPackage("com.google.android.gm");
startActivity(Intent.createChooser(Email, "Send mail"));
If you want subject and content use the code like how you added the lines for subject.
I have 2 EditTexts. EditText1 is in MainActivity, EditText2 is in SecondActivity.
EditText1 is to login (password), EditText2 is to change password.
My code looks like this:
EditText editText1 = findViewById(R.id.login);
editText2 = findViewById(R.id.changePassword); // declared in SecondActivity
if (editText1.getText().toString().equals(editText2.getText().toString())
{
Intent intent = new Intent (MainActivity.this, SecondActivity.class);
startActivity(intent);
}
else
{
Toast.makeText(MainActivity.this, "Password incorrect", Toast.Length_Long).show;
}
When I press Button to login, it shows me an error. I know it has to be initialized in a different way but how?
I tried another code with a Dialog and everything worked perfectly:
changePasswordDialog = new Dialog(MainActivity.this);
changePasswordDialog.setContentView(R.layout.activity_second_activity);
editText2 = changePasswordDialog.findViewById(R.id.changePassword);
So it works perfectly with Dialog, but how does it work without Dialog?
Try Like this
Store edit text 2 pass
String pass = editText2.getText().toString().trim();
SharedPreferences.Editor editor = getSharedPreferences(My_Prefs,Context.MODE_PRIVATE).edit();
editor.putString("pass", pass);
editor.apply();
Now Retrive the stored passwod in MainActivity
SharedPrefrences prefrences = getSharedPrefrences(My_Prefs,Context.MODE_PRIVATE);
String pass = prefrences.getString("pass","");
if (editText1.getText().toString().equals(pass)
{
Intent intent = new Intent (MainActivity.this, SecondActivity.class);
startActivity(intent);
}
You can use intent put extra and intent get extra for this
/// you can use this as per your requirement or you can use sharedprefrence///
// In main activity ///
Intent intent = new Intent (MainActivity.this, SecondActivity.class);
intent.putExtra("editText1",editText1.getText().toString());
startActivity(intent);
/// In second activity//
String passWord = getIntent().getExtras().getString("editText1");
Log.d("password : ",passWord);
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
}
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.
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 :"));
}
});