Tôi hiện đang làm việc trên ứng dụng Android có biểu mẫu đơn đặt hàng. Tôi muốn biết làm thế nào tôi có thể cho phép ứng dụng nắm bắt những gì người dùng đã nhập và gửi đầu vào trực tiếp đến một email bằng cách sử dụng nút, mà không cần đưa người dùng đến trang ứng dụng email. Tôi biết lớp .java của tôi có lỗi, tuy nhiên, tôi đang cố gắng ... Dưới đây là tệp xml (bố cục) của tôi và tệp lớp .java của tôi. Xin hãy giúp tôi ... Cảm ơn !!Ghi dữ liệu người dùng nhập và gửi trực tiếp đến địa chỉ email bằng cách sử dụng nút
Đây là tập tin .xml của tôi (bố trí)
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TextView
android:id="@+id/txtname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "
/>
<EditText
android:id="@+id/editname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtname"
android:hint="Your name please"
/>
<TextView
android:id="@+id/txtemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editname"
android:text="Email Address: "
/>
<EditText
android:id="@+id/editemail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtemail"
android:hint="Enter email address here"
/>
<TextView
android:id="@+id/txtnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editemail"
android:text="Contact Number: "
/>
<EditText
android:id="@+id/editnum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtnum"
android:hint="Enter contact number here"
/>
<TextView
android:id="@+id/txtadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editnum"
android:text="Mailing Address: "
/>
<EditText
android:id="@+id/editadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtadd"
android:hint="Enter mailing address here"
/>
<TextView
android:id="@+id/txtitems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editadd"
android:text="Item(s): "
/>
<EditText
android:id="@+id/edititems"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtadd"
android:hint="Enter item(s) here"
/>
<Button
android:id="@+id/btn_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/edititems"
android:text="Submit form"
/>
</TableLayout>
Đây là mã lớp java của tôi
public class OrderFormActivity extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.orderform);
Button btnsubmit = (Button)findViewById(R.id.btn_submit);
btnsubmit.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == this.findViewById(R.id.btn_submit)) {
EditText name = (EditText)findViewById(R.id.editname);
String strname = name.getText().toString();
EditText email = (EditText)findViewById(R.id.editemail);
String stremail = email.getText().toString();
EditText num = (EditText)findViewById(R.id.editnum);
String strnum = num.getText().toString();
EditText add = (EditText)findViewById(R.id.editadd);
String stradd = add.getText().toString();
EditText items = (EditText)findViewById(R.id.edititems);
String stritems = items.getText().toString();
showOrder(strname, stremail, strnum, stradd,stritems);
}
}
private void showOrder (String strname, String stremail, String strnum, String stradd, String stritems) {
String result = strname + stremail + strnum + stradd + stritems;
//Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String emailAddress = "[email protected]";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
intent.putExtra(Intent.EXTRA_TEXT, result);
}
}
Cảm ơn sẽ một lần nữa trước !!! : D
Sử dụng android: onClick trong XML trên nút và sau đó thực hiện chức năng cho lần nhấp nút. Sau đó, bạn không cần thử nghiệm đó cho v == ... – trgraglia
Xem http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android -app – PearsonArtPhoto
Cảm ơn tất cả vì phản ứng nhanh. -trgraglia, tôi nghĩ đó không phải là vấn đề chính bởi vì những gì tôi đang cố gắng làm bây giờ là gửi email ghi lại tất cả người dùng nhập vào một địa chỉ email cụ thể chỉ với một nút bấm. -Pearsonartphoto, cảm ơn câu trả lời, tuy nhiên, có cách nào ngắn hơn để thực hiện điều đó không? Bởi vì tôi thấy rằng giải pháp quá cồng kềnh .. Xin lỗi! – Winona