我正在尝试设置默认电子邮件地址,该位置将存储来自我的android应用程序的反馈,我可以让他们阅读。但是,我无法做到这一点。此外,您能建议我其他更好的方法来存储应用程序用户的反馈信息,以便以后阅读吗?
这是我的代码:
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>
答案 0 :(得分:0)
一种选择是通过电子邮件应用程序向您发送电子邮件。在这种情况下,您可以从editText获得用户反馈并通过它而不是“电子邮件正文”
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();
}
});
我建议使用AlertDialog.Builder而不是Dialog。
答案 1 :(得分:0)
一种简单的解决方案是将TextView
放在Navigation Drawer
或About activity
中,并具有以下属性:
android:autoLink="email"
android:text="youremail@host.com"
用户只需点击您的电子邮件,邮件应用就会启动...
至于其他部分,请确保您不散发您的个人电子邮件。
最好使用专业电子邮件或专用于该应用程序的电子邮件。
答案 2 :(得分:0)
您可以执行此操作以获取有关设备信息的反馈。
feedback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendFeedback();
}
});
public void sendFeedback() {
String body = null;
try {
body = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
body = "\n\n--------------\n" +
"Please don't remove this information" +
"\n Device OS: Android " +
"\n Device OS Version: " + Build.VERSION.RELEASE + "" +
"\n App Version: " + body + "" +
"\n Device Brand: " + Build.BRAND + "" +
"\n Device Model: " + Build.MODEL + "" +
"\n Device Manufacturer: " + Build.MANUFACTURER;
} catch (PackageManager.NameNotFoundException e) {
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "App Subject");
intent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(
Intent.createChooser(intent, getString(R.string.choose_email_client)));
}