has anyone know how to put/move this email send code to the service??
here’s the code :
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"myemail@hotmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
here’e my service code (Not Works and give me some “force close”):
@Override
public void onStart(Intent intent, int startid) {
//Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
sendEmail();
}
public void sendEmail()
{
Intent i = new Intent(Intent.ACTION_SEND);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"myemail@hotmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
getApplication().startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(EmailService.this,ex.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(EmailService.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
please help for solving my problem.. thanks..
That is not possible via
ACTION_SEND. You will need to integrate your own SMTP library (there’s an Android port of JavaMail available someplace) if you want to send email without user involvement.Use
adb logcat, DDMS, or the DDMS perspective in Eclipse to examine LogCat and look at the stack trace associated with your “Force Close”.Also, do not use
getApplication(), as you do not need it.