1

I have created a simple UI for my feedbackFragment, where I have created a submit button. I want that whenever any user fills up all edit texts or blank fields as showed in the screenshot & when the user presses the submit button, all filled contents will be sent to my email address.

enter image description here

public class Feedback extends Fragment {
    public View onCreateView(@NonNull LayoutInflater inflater,
                                 ViewGroup container, Bundle savedInstanceState)
    {
      View root = inflater.inflate(R.layout.activity_feedback, container, false);
       return root;
    }
}

I have provided you my Feedback.java code block.

Buddy
  • 581
  • 2
  • 11

1 Answers1

1

You can use Intent to send your filled contents to your email like the following:

private void sendEmail() {
  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, "Email message goes here");
  
  try {
     startActivity(Intent.createChooser(emailIntent, "Send mail..."));
     finish();
  } catch (android.content.ActivityNotFoundException ex) {
     Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
  }
}

You can then invoke this method from your submit button onClick like the following:

Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        sendEmail();
    }
});
SaadAAkash
  • 3,065
  • 3
  • 19
  • 25
  • i cannot understand how to implement your code in my project – Buddy Nov 12 '20 at 05:24
  • I've added more code snippets on how to invoke the method from your submit button on click, please have a look and let us know which part you're not understanding - invoke the method from your submit button as showed in the code @Buddy – SaadAAkash Nov 12 '20 at 05:28
  • I have upvote your answer but i am using another way. – Buddy Nov 12 '20 at 14:07
  • Hey brother check my new question https://stackoverflow.com/questions/65024641/download-pdf-and-open-it-in-google-doc-with-download-notification @SaadAAkash – Buddy Nov 27 '20 at 10:23