我在使用应用程序时遇到了一个问题。这个应用程序的目的是收集数据并使用javamail将数据表单提交到指定的电子邮件地址。当用户单击按钮时,他们应该收到一个提示选择电子邮件客户端,但是当我测试它时,我没有得到这个提示。有人能告诉我我漏掉了什么吗?
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class SubmitForm extends Activity implements View.OnClickListener {
private Intent emailIntent;
EditText personsFirstName, personsLastName, personsEmail, personsPhone, comments, vehicleModel;
Spinner vehicleYear, vehicleMake, serviceTime, serviceNeeded;
TextView serviceDate;
String fname, lname, emailAdd, phoneNumber, vehicleYears, vehicleModeltrim, vehicleManu, serviceAppointment, serviceAppointmentTime, serviceTypeNeeded, extraComments;
Button sendEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.service);
initializeVars();
sendEmail.setOnClickListener(this);
}
private void initializeVars() {
// TODO Auto-generated method stub
personsFirstName = (EditText) findViewById(R.id.firstName);
personsLastName = (EditText) findViewById(R.id.lastName);
personsEmail = (EditText) findViewById(R.id.Email);
personsPhone = (EditText) findViewById(R.id.PhoneNumber);
vehicleYear = (Spinner) findViewById(R.id.sYear);
vehicleMake = (Spinner) findViewById(R.id.sMake);
vehicleModel = (EditText) findViewById(R.id.Model);
serviceDate = (TextView) findViewById(R.id.Model);
serviceTime = (Spinner) findViewById(R.id.sTime);
serviceNeeded = (Spinner) findViewById(R.id.sNeeded);
comments = (EditText) findViewById(R.id.eComments);
sendEmail = (Button) findViewById(R.id.bSubmit);
}
public void onClick(View v) {
// TODO Auto-generated method stub
convertToString();
String emailaddress[] = { emailAdd };
String message = "Please Review the following"
+ '\n' + " "
+ '\n' + "First Name: " + fname
+ '\n' + "Last Name: " + lname
+ '\n' + "Email :" + emailAdd
+ '\n' + "Phone Number: " + phoneNumber
+ '\n' + "Vechile Year: " + vehicleYears
+ '\n' + "Vehicle Make: " + vehicleManu
+ '\n' + "Vehicle Model: " + vehicleModeltrim
+ '\n' + "Requested Service Date: " + serviceAppointment
+ '\n' + "Requested Service Time: " + serviceAppointmentTime
+ '\n' + "Service Needed: " + serviceTypeNeeded
+ '\n' + "Comments: " + extraComments;
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"test@someemail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Schedule Service Request");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(emailIntent, "Please select Email Client"));
}
private void convertToString() {
// TODO Auto-generated method stub
fname = personsFirstName.getText().toString();
lname = personsLastName.getText().toString();
emailAdd = personsEmail.getText().toString();
phoneNumber = personsPhone.getText().toString();
//vehicleYears = vehicleYear.getText().toString();
vehicleYears = (String) vehicleYear.getAdapter().getItem(RESULT_OK);
//vehicleManu = vehicleMake.getText().toString();
vehicleManu = (String) vehicleMake.getAdapter().getItem(RESULT_OK);
vehicleModeltrim = vehicleModel.getText().toString();
serviceAppointment = serviceDate.getText().toString();
serviceAppointmentTime = (String) serviceTime.getAdapter().getItem(RESULT_OK);
//serviceTypeNeeded = serviceNeeded.getText().toString();
serviceTypeNeeded = (String) serviceNeeded.getAdapter().getItem(RESULT_OK);
extraComments = comments.getText().toString();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"test@someemail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
- ρяσѕρєя KemailIntent.setType("plain/text")
替换为emailIntent.setType("text/plain")
。 - ρяσѕρєя K