0

当邮件发送成功为“消息已发送”时,我想要祝酒,而当错误发送不成功时,则为“消息未发送”

怎么做...谢谢

class RetreiveFeedTask extends AsyncTask<String, Void, String> {

    protected String doInBackground(String... urls) {
        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("example@gmail.com"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(recpient));
            message.setSubject(subject);
            message.setReplyTo(InternetAddress
                    .parse("example@gmail.com"));
            message.setContent(
                    textmessage,
                    "text/html; charset=utf-8");

            Transport.send(message);

        } catch (MessagingException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    protected void onPostExecute(String feed) {
        pdialog.dismiss();
        reciept.setText("");
        msg.setText("");
        sub.setText("");
        Toast.makeText(getApplicationContext(), "Message sent",
                Toast.LENGTH_LONG).show();

    }
}
4

2 回答 2

0

String你返回的是doInBackground你得到的参数onPostExecute

null当一切正常时,您可以返回,e.getMessage()如果发生任何Exception情况。然后,onPostExecute显示确认 toast if feedis null,或者错误 is not 。

于 2013-09-29T10:16:12.023 回答
0

创建处理程序

private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg)
    {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }
};

和一个变量private String message = "" ,并doInBackground相应地改变它的值,即message="Mail Sent";或每当你想显示吐司时message="Mail Not Sent";调用handler.sendEmptyMessage(0);

于 2013-09-29T11:05:19.157 回答