设置默认电子邮件或其他地址以获取用户反馈

Set default email or other address to get feedback from user

我正在尝试设置默认电子邮件地址,用于存储来自我的 android 应用程序的反馈,我可以让他们阅读。但是,我做不到 it.Also,你能建议我其他更好的方法来存储你的应用程序用户的反馈,我可以稍后阅读吗?

这是我的代码:

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>

一种选择是通过电子邮件应用程序向您发送电子邮件。在这种情况下,您可以从您的 editText 获得用户反馈并传递它而不是 "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();
        }
    });

而且我建议使用 AlertDialog.Builder 而不是 Dialog。

一个简单的解决方案是在 Navigation DrawerAbout activity 中添加一个 TextView 并具有以下属性:

android:autoLink="email"
android:text="youremail@host.com"

有了这个,用户只需单击您的电子邮件,邮件应用程序就会启动...
至于另一部分,请确保您不要泄露您的个人电子邮件。
最好使用专业的电子邮件或专门针对该应用程序的电子邮件。

您可以执行此操作以获取有关设备信息的反馈。

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)));
  }