我不知道的电子邮件发送的一部分,但我可以帮助你做出的消息框喜欢你想要。
如果删除下面的代码:
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { // define the 'OK' button
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
然后对话框将显示,没有按键,如果你添加.setCancelable(false)
它不会被解雇,直到你告诉它,使用alertDialog.cancel();
这里的一个示例(修改从我的对话中的一个):
AlertDialog.Builder builder = new AlertDialog.Builder(this); // Create the dialog object
builder.setMessage(R.string.dialog_disclaimer_text) // I use a reference to a string resource - it's good practice instead of using hardcoded text
.setIcon(android.R.drawable.ic_dialog_info) // Here I specify an icon to be displayed in the top corner
.setTitle(R.string.dialog_disclaimer_title)
.setCancelable(false) // This one makes the dialog stay until the dismiss is called
.create().show(); // Show the dialog
该代码将显示一个对话框,文本,这将在活动调用builder.dismiss();
之前不会消失 - 然后您必须在某种侦听器中实现该功能,或者在完成发送后进行回调。在对方的回答
更新
来看,这可能是你的代码应该怎么样子(感谢iturki)
private class SendEmailTask extends AsyncTask<Void, Void, Void> {
AlertDialog.Builder alertDialog; // Define the AlertDialog builder object so it can be used/adressed across the entire class
protected void onPreExecute() {
//Show the dialog first
alertDialog = new Builder(context);
alertDialog.setTitle("Sending...")
.setMessage("Please wait while your details and image is being sent to x.");
.setCancelable(false)
.show();
}
protected void doInBackground(Void... params) {
//Send Email Code
Reusable_CodeActivity.send_email(gmailAC, gmpassword, get_all_details(), image_path, this);
}
protected void onPostExecute(Void result) {
//Dismiss the dialog
alertDialog.dismiss();
}
}
你是什么意思'不working'? – iTurki 2012-08-12 23:50:59
它在警告框出现之前开始发送电子邮件。 – omega 2012-08-12 23:52:47
您是否将电子邮件发送功能置于单独的线程中? – iTurki 2012-08-12 23:54:41