0

I've a feedback form and buttons for send and cancel. How can I make the feedback send responds to a default email when the send button is clicked? And how can I set a the default email. Is this possible? Please let me know. Thank you.

Here's is my java for the feedback form :

            @Override
            public void onClick(View arg0) {

                // Create custom dialog object
                final Dialog dialog = new Dialog(MainActivity.this);
                // Include dialog.xml file
                dialog.setContentView(R.layout.activity_main);
                // Set dialog title
                dialog.setTitle("Feedback"); 

                dialog.show();

                Button button1 = (Button) dialog.findViewById(R.id.button1);
                // if decline button is clicked, close the custom dialog
                button1.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // Close dialog
                        dialog.dismiss();
                    }
                });

                Button button2 = (Button) dialog.findViewById(R.id.button2);
                // if decline button is clicked, close the custom dialog
                button2.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // Close dialog
                        dialog.dismiss();
                    }
                });

Feedback Form

Iman Yasmin
  • 447
  • 2
  • 11
  • 31
  • also you can see this link http://stackoverflow.com/questions/3312438/how-to-open-email-program-via-intents-but-only-an-email-program – Vivek Mishra Sep 27 '16 at 10:22

2 Answers2

2

Open your email client programatically using a chooser:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some@email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));

To send email programatically without using chooser,you can use this link.

Community
  • 1
  • 1
kgandroid
  • 5,507
  • 5
  • 39
  • 69
1

You can use following snippet:

     private void sendEmail(String email) {

                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);

                    String aEmailList[] = {email};
                    emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle this
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
                    String feedback_msg = getString(R.string.feedback_msg);
                    emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<i><font color='your color'>" + feedback_msg + "</font></i>"));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_msg));

                    PackageManager packageManager = getActivity().getPackageManager();
                    boolean isIntentSafe = emailIntent.resolveActivity(packageManager) != null;
                    if (isIntentSafe) {
                        startActivity(emailIntent);
                    } else {
                        Toast.makeText(getActivity(), R.string.email_app_not_installed, Toast.LENGTH_SHORT).show();
                    }
                } 
   }
Ram Prakash Bhat
  • 1,308
  • 12
  • 21