Android使用电子邮件地址列表发送电子邮件

Android使用电子邮件地址列表发送电子邮件,android,email,Android,Email,我已经创建了一个应用程序,其中内置了一个表单,目前正在发送到一个预先确定的电子邮件地址。有没有一种方法可以根据用户在表单中按的内容自动添加电子邮件地址,而不是根据发送到的电子邮件地址创建十几个版本的应用程序?i、 e单击滚动条中的美国,它会自动将美国电子邮件地址放入要发送的电子邮件中 如果有的话,有没有任何人可以给我指点的教程或例子 我已在下面附上我的代码: import java.util.Calendar; import android.app.Activity; import androi

我已经创建了一个应用程序,其中内置了一个表单,目前正在发送到一个预先确定的电子邮件地址。有没有一种方法可以根据用户在表单中按的内容自动添加电子邮件地址,而不是根据发送到的电子邮件地址创建十几个版本的应用程序?i、 e单击滚动条中的美国,它会自动将美国电子邮件地址放入要发送的电子邮件中

如果有的话,有没有任何人可以给我指点的教程或例子

我已在下面附上我的代码:

import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class NearMiss extends Activity {

    Button send;
    protected static final int CAMERA_PIC_REQUEST = 0;
    private TextView tvDisplayDate;

    private Button btnChangeDate;


    private int year;
    private int month;
    private int day;


    static final int DATE_DIALOG_ID = 999;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nearmiss);

        Button camera = (Button) findViewById(R.id.button2); 
        camera.setOnClickListener(new View.OnClickListener() { 
            public void onClick(View view) {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                  startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
    ;

                }     
            });  



        setCurrentDateOnView();
        addListenerOnButton();


    }


    // display current date
        public void setCurrentDateOnView() {
            tvDisplayDate = (TextView) findViewById(R.id.EditTextDate);

            final Calendar c = Calendar.getInstance();
            year = c.get(Calendar.YEAR);
            month = c.get(Calendar.MONTH);
            day = c.get(Calendar.DAY_OF_MONTH);
            // set current date into textview
            tvDisplayDate.setText(new StringBuilder()
                    // Month is 0 based, just add 1
                    .append(day).append("-").append(month + 1).append("-")
                    .append(year).append(" "));

        }
        public void addListenerOnButton() {
            btnChangeDate = (Button) findViewById(R.id.btnChangeDate);
            btnChangeDate.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    showDialog(DATE_DIALOG_ID);
                }
            });
        }
        @Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DATE_DIALOG_ID:
                // set date picker as current date
                return new DatePickerDialog(this, datePickerListener, year, month,
                        day);
            }
            return null;
        }
        private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
            // when dialog box is closed, below method will be called.
            public void onDateSet(DatePicker view, int selectedYear,
                    int selectedMonth, int selectedDay) {
                year = selectedYear;
                month = selectedMonth;
                day = selectedDay;
                // set selected date into textview
                tvDisplayDate.setText(new StringBuilder().append(day)
                        .append("-").append(month + 1).append("-").append(year)
                        .append(" "));

            }
        };



    public void sendFeedback(View button) {

        final EditText nameField = (EditText) findViewById(R.id.EditTextName);
        String name = nameField.getText().toString();

        final EditText emailField = (EditText) findViewById(R.id.EditTextEmail);
        String email = emailField.getText().toString();

        final EditText feedbackField = (EditText) findViewById(R.id.EditTextFeedbackBody);
        String feedback = feedbackField.getText().toString();

        final Spinner feedbackSpinner = (Spinner) findViewById(R.id.SpinnerFeedbackType);
        String feedbackType = feedbackSpinner.getSelectedItem().toString();

        final EditText dateField = (EditText) findViewById(R.id.EditTextDate);
        String date = dateField.getText().toString();
        final EditText timeField = (EditText) findViewById(R.id.EditTextTime);
        String time = timeField.getText().toString();

        final Spinner feedbackLocation = (Spinner) findViewById(R.id.SpinnerLocationType);
        String locationType = feedbackLocation.getSelectedItem().toString();

        final EditText contactField = (EditText) findViewById(R.id.EditTextContact);
        String contact = contactField.getText().toString();

        final Spinner feedbackOperative = (Spinner) findViewById(R.id.SpinnerOperativeType);
        String operativeType = feedbackOperative.getSelectedItem().toString();

        final CheckBox responseCheckbox = (CheckBox) findViewById(R.id.CheckBoxResponse);
        boolean bRequiresResponse = responseCheckbox.isChecked();


        // Take the fields and format the message contents
        String subject = formatFeedbackSubject(feedbackType);
        String message = formatFeedbackMessage(feedbackType, name,
             email, feedback, date, time, locationType, operativeType, bRequiresResponse, contact);

        // Create the message
        sendFeedbackMessage(subject, message);
    }

    protected String formatFeedbackSubject(String feedbackType) {

        String strFeedbackSubjectFormat = getResources().getString(
                R.string.feedbackmessagesubject_format);
        String strFeedbackSubject = String.format(strFeedbackSubjectFormat, feedbackType);

        return strFeedbackSubject;
    }

    protected String formatFeedbackMessage(String feedbackType, String name,
            String email, String feedback, String date, String time, String locationType, String operativeType, boolean bRequiresResponse, String contact) {

        String strFeedbackFormatMsg = getResources().getString(
                R.string.feedbackmessagebody_format);
        String strRequiresResponse = getResponseString(bRequiresResponse);
        String strFeedbackMsg = String.format(strFeedbackFormatMsg,
                name, email, date, time, feedbackType, feedback, locationType, operativeType, strRequiresResponse, contact);

        return strFeedbackMsg;
    }

    protected String getResponseString(boolean bRequiresResponse)
    {
        if(bRequiresResponse==true)
        {
            return getResources().getString(R.string.feedbackmessagebody_responseyes);
        } else {
            return getResources().getString(R.string.feedbackmessagebody_responseno);
        }

    }
    public void sendFeedbackMessage(String subject, String message) {
        Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);
        String aEmailList[] = { "uk@abc.com", "usa@abc.com" };
        messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
        messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        messageIntent.setType("plain/text");
        messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
        startActivity(messageIntent);




    }
} 
和.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/mainscreenc"
        android:orientation="vertical" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="125dip"
            android:background="@drawable/title" >

        </TableRow>

        <EditText
            android:id="@+id/EditTextName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dip"
            android:hint="@string/feedbackname"
            android:inputType="textPersonName"
            android:textColor="@color/red" >
</EditText>

        <EditText
            android:id="@+id/EditTextEmail"
            android:layout_height="wrap_content"
            android:hint="@string/feedbackemail"
            android:inputType="textEmailAddress"
            android:layout_width="fill_parent"
            android:textColor="@color/red" ></EditText>

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="20dip"
            android:text="Category of Near Miss:"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black" />

        <Spinner
            android:id="@+id/SpinnerFeedbackType"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dip"
            android:entries="@array/feedbacktypelist"
            android:prompt="@string/feedbacktitle" 
            android:textColor="@color/red" >
</Spinner>

        <EditText
            android:id="@+id/EditTextFeedbackBody"
            android:layout_height="wrap_content"
            android:hint="@string/feedbackbody"
            android:inputType="textMultiLine"
            android:lines="5"
            android:layout_width="fill_parent"
            android:textColor="@color/red" ></EditText>

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="20dip"
            android:text="Date of Near Miss:" 
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black" />

    <EditText
            android:id="@+id/EditTextDate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="Approximate Date of Near Miss" 
            android:textColor="@color/red" >
            </EditText>

    <Button
        android:id="@+id/btnChangeDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dip"
        android:text="Change Date" />

        <EditText
            android:id="@+id/EditTextTime"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="Approximate Time of Near Miss" 
            android:textColor="@color/red" >

        </EditText>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="20dip"
            android:text="Location Of Near Miss:"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black" />

        <Spinner
            android:id="@+id/SpinnerLocationType"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dip"
            android:entries="@array/locationtypelist"
            android:prompt="@string/locationtitle"  
            android:textColor="@color/red" >
</Spinner>

         <TextView
             android:id="@+id/textView2"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginLeft="10dip"
             android:text="Your Main Office:"
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:textColor="@color/black" />

        <Spinner
            android:id="@+id/SpinnerOperativeType"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dip"
            android:entries="@array/operativetypelist"
            android:prompt="@string/officetitle"  
            android:textColor="@color/red" >
</Spinner>

        <CheckBox
            android:id="@+id/CheckBoxResponse"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dip"
            android:text="@string/feedbackresponse"
            android:textColor="@color/black" >
</CheckBox>

        <EditText
            android:id="@+id/EditTextContact"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="Contact Number" 
            android:textColor="@color/red" >

        </EditText>

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="10dip"
            android:text="Take Photo" />

        <Button
            android:id="@+id/ButtonSendFeedback"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dip"
            android:layout_marginTop="15dip"
            android:onClick="sendFeedback"
            android:text="@string/feedbackbutton" >
</Button>


    </LinearLayout>
</ScrollView>

非常感谢

您可以通过使用键值对实现微调器来实现
valueTextView=(TextView)findviewbyd(R.id.selected);
微调器s=(微调器)findViewById(R.id.Spinner);
最终MyData项目[]=新MyData[3];
项目[0]=新的MyData(“美国”us@abc.com" );
第[1]项=新的MyData(“印度”)india@abc.com" );
项目[2]=新的MyData(“英国”uk@abc.com" );
ArrayAdapter=新的ArrayAdapter此,android.R.layout.simple\u微调器\u项,项);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
s、 设置适配器(适配器);
s、 setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener()
{
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id)
{
MyData d=项目[位置];
valueTextView.setText(d.getValue());
}
未选择公共无效(AdapterView父级)
{
}
}
);
类MyData{
公共MyData(字符串微调器文本、字符串值){
this.spinnerText=spinnerText;
这个值=值;
}
公共字符串getSpinnerText(){
返回喷丝头文本;
}
公共字符串getValue(){
返回值;
}
公共字符串toString(){
返回喷丝头文本;
}
字符串喷丝板文本;
字符串值;
}

非常感谢。但是,我在将您的代码集成到我的代码时遇到了问题。它带来了一系列的错误。我已经附上了表单的Java和xml代码。我希望人们能够选择他们的位置,从而选择电子邮件发送的电子邮件地址。我将非常感谢你的帮助。
  valueTextView = (TextView)findViewById( R.id.selected );
   Spinner s = (Spinner)findViewById(R.id.spinner);
    final MyData items[] = new MyData[3];
    items[0] = new MyData( "US","us@abc.com" );
    items[1] = new MyData( "INDIA","india@abc.com" );
    items[2] = new MyData( "UK","uk@abc.com" );
    ArrayAdapter<MyData> adapter = new ArrayAdapter<MyData>this,android.R.layout.simple_spinner_item,items);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s.setAdapter(adapter);
    s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
     {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) 
            {
                MyData d = items[position];
                valueTextView.setText( d.getValue() );
            }

            public void onNothingSelected(AdapterView<?> parent) 
            {
            }
        }
    );


   class MyData {
    public MyData( String spinnerText, String value ) {
        this.spinnerText = spinnerText;
        this.value = value;
    }

    public String getSpinnerText() {
        return spinnerText;
    }

    public String getValue() {
        return value;
    }

    public String toString() {
        return spinnerText;
    }

    String spinnerText;
    String value;
}