0

i'm fairly new to java and i'm having a problem with email intents. I am developing an app and i made an email intent but i dont know how to make sure that the recipient field isn't the result of the user input in an edit text box, i want that removed so it only shows the "subject" and "message" box in the app. i want the recipient field already filled when you tap "send". Here is my code

 editTextSubject=(EditText)findViewById(R.id.editText2);
    editTextMessage=(EditText)findViewById(R.id.editText3);

    send=(Button) findViewById(R.id.button1);

    send.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View arg0) {

            String[] recipients = new String[]{"email@gmail.com"};
            String subject=editTextSubject.getText().toString();
            String message=editTextMessage.getText().toString();





            Intent email = new Intent(Intent.ACTION_SEND);
            email.putExtra(Intent.EXTRA_EMAIL, recipients );
            email.putExtra(Intent.EXTRA_SUBJECT, subject);
            email.putExtra(Intent.EXTRA_TEXT, message);

            email.setType("message/rfc822");
            startActivity(Intent.createChooser(email,"Choose an Email client :"));

1 Answers1

0

Here the code I used to send a new email

   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)));
        }
MarionFlex
  • 92
  • 4