4

我是编码的新手,这是我的第一个应用程序,我想用我的表单中的条目填充电子邮件的正文。我整天都在努力让它工作,只是还没弄清楚,任何帮助将不胜感激。控制台中的日志条目反映了表单输入,但未填充电子邮件。提前致谢,

这是我到目前为止的代码。

<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/scrollView1"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/appDiscription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/discription_text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Spinner
        android:id="@+id/employeeSpinner"
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:entries="@array/employeeSpinner"
        android:prompt="@string/employeeSpinner" />

    <Spinner
        android:id="@+id/jobTypeSpinner"
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:entries="@array/jobTypeSpinner"
        android:prompt="@string/jobTypeSpinner" />

    <EditText
        android:id="@+id/jobDateText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/job_date_text"
        android:inputType="date" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/clientText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/client_text"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/arrivalText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/arrival_text"
        android:inputType="time" />

    <EditText
        android:id="@+id/departureText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/departure_text"
        android:inputType="time" />

    <EditText
        android:id="@+id/assignmentText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/assignment_text" 
        android:inputType="textPersonName"/>

    <EditText
        android:id="@+id/notesText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/notes_text"
        android:inputType="textMultiLine" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:onClick="onClick"
        android:text="@string/submit_button" />
 </LinearLayout>


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;

public class AssignmentTracker extends Activity {

Spinner employeeSpinner;
Spinner jobTypeSpinner;
EditText clientText;
EditText jobDateText;
EditText arrivalText;
EditText departureText;
EditText assignmentText;
EditText notesText;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    employeeSpinner = (Spinner) findViewById(R.id.employeeSpinner);
    jobTypeSpinner = (Spinner) findViewById(R.id.jobTypeSpinner);
    clientText = (EditText) findViewById(R.id.clientText);
    jobDateText = (EditText) findViewById(R.id.jobDateText);
    arrivalText = (EditText) findViewById(R.id.arrivalText);
    departureText = (EditText) findViewById(R.id.departureText);
    assignmentText = (EditText) findViewById(R.id.assignmentText);
    notesText = (EditText) findViewById(R.id.notesText);


}
public void onClick(View v) {
    String employeeType = employeeSpinner.getSelectedItem().toString();
    String jobType = jobTypeSpinner.getSelectedItem().toString();
    String nameText = clientText.getText().toString();
    String dateText = jobDateText.getText().toString();
    String arrivalType = arrivalText.getText().toString();
    String departureType = departureText.getText().toString();
    String assignText = assignmentText.getText().toString();
    String noteText = notesText.getText().toString();

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
            "Daily Worksheet");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Employee:"
            + employeeSpinner.getSelectedItem().toString());

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Job Type:"
            + jobTypeSpinner.getSelectedItem().toString());

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Date:"
            + jobDateText.getText().toString());

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Client:"
            + clientText.getText().toString());

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Arrival Time:"
            + arrivalText.getText().toString());

    emailIntent.putExtra(android.content.Intent. EXTRA_TEXT,
            "Departure Time:" + departureText.getText().toString());

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Assignment:"
            + assignmentText.getText().toString());

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Notes:"
            + notesText.getText().toString());
    emailIntent.setType("plain/text");
    startActivity(emailIntent);

    Log.d("AssignmentTracker", "onClicked " + employeeType);
    Log.d("AssignmentTracker", "onClicked " + jobType);
    Log.d("AssignmentTracker", "onClicked " + nameText);
    Log.d("AssignmentTracker", "onClicked " + dateText);
    Log.d("AssignmentTracker", "onClicked " + arrivalType);
    Log.d("AssignmentTracker", "onClicked " + departureType);
    Log.d("AssignmentTracker", "onClicked " + assignText);
    Log.d("AssignmentTracker", "onClicked " + noteText);
4

1 回答 1

0

您只能设置电子邮件地址、主题和正文等字段。

您可以从您拥有的字段中编写正文文本并如下发送。

try {
        final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("plain/text");
        if (recipient != null)  intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{to});
        if (subject != null)    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        if (message != null)    intent.putExtra(android.content.Intent.EXTRA_TEXT, message);

        startActivity(Intent.createChooser(intent, "Send mail..."));

    } catch (ActivityNotFoundException e) {

    }
于 2012-10-10T20:10:23.933 回答