


Next, I will add the Button to MainActivity.java file and set an OnClickListener.

To add Button in Android project, I will open the XML layout of MainActivity.java ( activity_main.xml) and add the following lines: I have created a very simple project with one MainActivity. To be able to follow this tutorial you will need to have an Android project created. This is how we can send emails using intents in android applications based on our requirements.In this short Android tutorial I am going to share with you how to start a new Activity when Button is clicked. For example, a UI button that would have sent feedback email using a mailto URL might instead open a web-based feedback form using an https URL on failure. By selecting the required email client we can send an email without building our own email client like as shown below. Once we enter all the details and click on Send button, it will display a dialog with the apps which are capable of sending an email.

When we run above program in the android studio we will get the result like as shown below. If you observe above AndroidManifest.xml file we added following extra fields of Intent filters.Īction - we use this property to define that the activity can perform SEND action.Ĭategory - we included the DEFAULT category for this activity to be able to receive implicit intents.ĭata - the type of data the activity can send. We need to add MIME type in our android manifest file for that open android manifest file ( AndroidManifest.xml) and write the code like as shown below AndroidManifest.xml Here we used “ message/rfc822” and other MIME types are “ text/plain” and “ image/jpg”. SetType - We use this property to set the MIME type of data that we want to send.
