在我的应用程序中,我想发送一封电子邮件。
我正在使用 AsyncTask 但如何识别电子邮件是否已送达,以便我可以在 postExecute 方法中停止进度条。请提供任何帮助。这是我的代码。给我发邮件就好了...
public class SendMainActivity extends Activity {
Button send = null;
EditText mailid = null;
String emailId = null;
ConnectivityManager conMan = null;
NetworkInfo Info = null;
ProgressBar pro = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
send = (Button)findViewById(R.id.button1);
mailid = (EditText)findViewById(R.id.editText1);
pro = (ProgressBar)findViewById(R.id.progressBar1);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Info = conMan.getActiveNetworkInfo();
emailId = mailid.getText().toString();
if(Info == null){
Toast.makeText(getApplicationContext(), "no net connection ", Toast.LENGTH_LONG).show();
}else{
new SendEmail().execute();
}
}
});
}
class SendEmail extends AsyncTask<Void, Void, Integer>{
@Override
protected void onPreExecute()
{
pro.setVisibility(View.VISIBLE);
pro.setProgress(0);
}
@Override
protected Integer doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
GmailSender sender = new GmailSender("usermailid@gmail.com", "userpass");
sender.sendMail("This is Subject",
"This is Body how r u ..",
"usermailid@gmail.com",
emailId);
} catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
return null;
}
@Override
protected void onPostExecute(Integer result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
pro.destroyDrawingCache();
}
}
}