2

I am trying to write a sample E-Mail application in Android.

My intensition is once i click on button it should open dafault mailing application with out ant chose menu.

my code is like below::

public void sendEmail(View v)
{
    String[] TO = {"amrood.admin@gmail.com"};
      String[] CC = {"mcmohd@gmail.com"};
      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_CC, CC);
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
      emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");

      try {
         //startActivity(Intent.createChooser(emailIntent, "Send mail..."));
          startActivity(emailIntent);
         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();
      }     
}

i don't need below screen:

I don't need this conformation screen

Krishna
  • 343
  • 1
  • 2
  • 9
  • 1
    [Check this answer](http://stackoverflow.com/a/19947819/3330969), perfectly working code. – Lucifer Apr 15 '14 at 13:29
  • 1
    This menu comes up be default because the user should have a choice how they want to handle their email. – John Apr 15 '14 at 13:30
  • That's the correct answer and there is no workaround. If you really want to get sure email is sent without user interaction, the only way to go is to javamail as @Kedamath pointed out. – Snicolas Apr 15 '14 at 13:30
  • 1
    @Kedarnath he doesn't want to send an email in the background, he wants the dialog to not popup. – John Apr 15 '14 at 13:31
  • @John, that menu comes when are using default email functionality of Android OS. But if you are doing it by coding then that menu will not come. – Lucifer Apr 15 '14 at 13:31
  • @John, both are same thing. – Lucifer Apr 15 '14 at 13:31
  • you mean to say it's **default Android behavior** – Krishna Apr 15 '14 at 13:32
  • @Kedarnath When you send an email in the background, the user sees nothing, it is hidden in the **background**. I think that the OP wants the user to be able to edit the email in the gmail application and just doesn't want the popup. `My intensition is once i click on button it should open dafault mailing application` - OP – John Apr 15 '14 at 13:34
  • @Kedarnath: Yes, what John is telling is correct. I don't want to see that poup after i clicked on the button and i want to directly goes to **default mailing**. – Krishna Apr 15 '14 at 13:38

1 Answers1

2

From what I understand from the problem this is what you want:

  1. The user clicks on a button
  2. No dialog window pops up
  3. The email opens up in the default mailing application

As we have pointed out in the comments, it is the default behavior for this dialog window to pop up. If this dialog window didn't pop up, then the user would not have a choice how to handle the email you are giving them to compose.

If the user wants, they can click the check mark on the dialog box to make that application the default application for handling email. Then the user will no longer get that popup. That is up to the user, not up to the developer.

You cannot get rid of this dialog window, it is meant to be there.

John
  • 3,769
  • 6
  • 30
  • 49
  • Not 100% agree with you John, If you dont use Intent with default OS email functionality then you can send email programmatically without any user interaction. – Lucifer Apr 16 '14 at 03:02
  • @Kedarnath you don't understand what the developer is trying to accomplish. Yes you can send an email in the background, but that's not what he is trying to accomplish. Read the post again, you are missing the point. – John Apr 16 '14 at 03:15
  • 1
    @Kedarnath no harm done, your argument was very constructive while I was compiling my answer =) – John Apr 16 '14 at 03:22