【问题标题】:Set default email or other address to get feedback from user设置默认电子邮件或其他地址以获取用户的反馈
【发布时间】:2019-01-22 10:26:40
【问题描述】:

我正在尝试设置默认电子邮件地址,用于存储来自我的 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>

【问题讨论】:

  • 我做不到 -- 为什么不做
  • 我尝试使用:Intent browser = new Intent(Intent.ACTION_SEND, Uri.parse("myemailaddress@gmail.com"));

标签: java android feedback


【解决方案1】:

一种选择是通过电子邮件应用程序向您发送电子邮件。在这种情况下,您可以从您的 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。

【讨论】:

    【解决方案2】:

    一个简单的解决方案是在 Navigation DrawerAbout activity 中使用具有以下属性的 TextView

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

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

    【讨论】:

      【解决方案3】:

      您可以这样做来获取设备信息反馈。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-25
        • 1970-01-01
        • 2013-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-12
        • 1970-01-01
        相关资源
        最近更新 更多