Email feedback from your App in Android Studio With Step by Step Guide

Send Email feedback from your App in Android Studio

In this tutorial we will learn to create a feedback for your App, where the user can give his views and feedback regarding your App.

The steps for creating App is given below and you can also download the file given at the end of this Tutorial

 

Step1: Create a project with Project name as EmailExample and domain name as codeally.com

 

Step 2: Select Blank Activity click on next . By default the name of layout file will be activity_main.xml and Activtiy will be MainActivity.java click on Finish

 

Step 3: Write the following code in activity_main.xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 

 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"  

android:layout_height="match_parent" 

 android:paddingLeft="@dimen/activity_horizontal_margin" 

 android:paddingRight="@dimen/activity_horizontal_margin" 

 android:paddingTop="@dimen/activity_vertical_margin"  

android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

 

    <TextView android:text="Your Name"

android:layout_width="wrap_content"     

android:layout_height="wrap_content"

        android:id="@+id/textView1"      

android:textSize="30dp" />

 

    <EditText        android:layout_width="match_parent" 

 android:layout_height="wrap_content"       

android:id="@+id/editText1"       

android:paddingLeft="20dp" 

 android:layout_alignParentTop="true" 

 android:layout_toRightOf="@+id/textView1"       

android:layout_toEndOf="@+id/textView1" />

    <TextView android:text="Message" 

 android:layout_width="wrap_content"       

android:layout_height="wrap_content"       

android:textSize="30dp" 

 android:paddingTop="10dp" 

 android:id="@+id/textView2" 

 android:layout_below="@+id/textView1"/>

 

    <EditText        android:layout_width="match_parent"       

android:layout_height="wrap_content" 

 android:id="@+id/editText2"       

android:paddingLeft="20dp"       

android:layout_below="@+id/editText1" 

 android:layout_toRightOf="@+id/textView2"       

android:layout_toEndOf="@+id/textView2"       

android:maxLines="5"        android:minLines="5" />

 

    <Button        android:layout_width="wrap_content"      

android:layout_height="wrap_content"      

android:text="Send"       

android:id="@+id/button" 

 android:singleLine="true" 

 android:layout_centerVertical="true" 

 android:layout_alignLeft="@+id/editText2" 

 android:layout_alignStart="@+id/editText2" />

 

</RelativeLayout>

 

Explanation: We are creating a layout with 2 Textviews and 2 EditText where we will accept input from the user. Then we have taken a button on which we will give a click event

 

Step 4: In MainActivity.java file write the following code:

 

package com.codeally.emailexample;
 
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
 
public class MainActivity extends ActionBarActivity {
    Button b;
    EditText e1,e2;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b=(Button)findViewById(R.id.button);
        e1=(EditText)findViewById(R.id.editText1);
        e2=(EditText)findViewById(R.id.editText2);
        b.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("message/html");
                i.putExtra(Intent.EXTRA_EMAIL, new String[]{"sumaiyabpatel@gmail.com"});
                i.putExtra(Intent.EXTRA_SUBJECT, "Feedback from App");
                i.putExtra(Intent.EXTRA_TEXT, "Name : "+e1.getText()+"\nMessage : "+e2.getText());
                try {
                    startActivity(Intent.createChooser(i, "Send feedback..."));
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
                }
 
            }
        });
 
    }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    @Override    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.       // getMenuInflater().inflate(R.menu.menu_main, menu);        return false;
    }
 
    @Override    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
 
        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {
            return true;
        }
 
        return super.onOptionsItemSelected(item);
    }
}