メール送信の部分はよくわかりませんが、メッセージボックスを希望通りにするお手伝いはできます。
次のコードを削除した場合:
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { // define the 'OK' button
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
次に、ダイアログはボタンなしで表示され、追加.setCancelable(false)
すると、指示するまで閉じられません。alertDialog.cancel();
これが例です(私のダイアログの1つから変更されました):
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();
}
}