I am trying to set default email address where the feedback from the my android application will be stored and I could get them to read. However, I am not able to do it.Also, could you suggest me other better ways to store feedback from user of your app which I could read later?
Here is my code:
activity_main.xml
<RelativeLayout android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent">
<Button
android:id="@+id/feedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/feedback"
android:textColor="#26A69A" />
</RelativeLayout>
feedback.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#D0ECE7 "
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="54dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/ftitle"
android:textColor="#26A69A"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="@string/feed"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:hint="Write Here"
android:background="#ffffff"
android:inputType="textPersonName"
android:textColor="#26A69A"
android:textColorLink="#26A69A" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:gravity="center"
android:text="@string/fSend"
android:textColor="#26A69A" />
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:gravity="center"
android:text="@string/fCancel"
android:textColor="#26A69A" />
</LinearLayout>
</LinearLayout>
MainActivity.java
package com.example.abina.feedback;
import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Dialog thisDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//for feedback
Button feedback = findViewById(R.id.feedback);
feedback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
thisDialog = new Dialog(MainActivity.this);
thisDialog.show();
thisDialog.setContentView(R.layout.feedback);
thisDialog.setTitle("Send Your Feedback");
thisDialog.getWindow().setDimAmount(0.5f);
EditText editText = thisDialog.findViewById(R.id.editText);
Button send = thisDialog.findViewById(R.id.send);
Button cancel = thisDialog.findViewById(R.id.cancel);
editText.setEnabled(true);
send.setEnabled(true);
cancel.setEnabled(true);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Your message is sent.",Toast.LENGTH_SHORT).show();
thisDialog.cancel();
}
});
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
thisDialog.cancel();
}
});
}
});
}
}
Strings.xml
<resources>
<string name="app_name">feedback</string>
<string name="feedback">Send us your Recomendation and feedback.</string>
<string name="ftitle">Recomendation</string>
<string name="feed">We are glad to have you. Please send us your feedback and suggestions to improve this application and make it easier for other to use.</string>
<string name="fSend">Send</string>
<string name="fCancel">Cancel</string>
</resources>
One option is to send e-mail to you via e-mail app. In this case you can get users feedback from your editText and pass it instead of "body of email"
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setType("message/rfc822");
i.setData(Uri.parse("mailto:"));
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"test@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
thisDialog.cancel();
}
});
And I recommend to use AlertDialog.Builder instead of Dialog.