In my application i want send a email to one account.in one button click event.i used the below code . this have exception
public void onClick(View v) {
sendEmail(context, new String[]{"jayampalaniraja@gmail.com"}, "Sending Email", "Test Email", "I am body");
}
private void sendEmail(Context context, String[] recipientList,
String subject, String body, String title) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipientList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
emailIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try
{
context.startActivity(Intent.createChooser(emailIntent, title));
}catch(Exception e)
{
System.out.println(e);
}
}
The exception I am getting as
"03-19 19:13:19.553: I/System.out(2010): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.
It’s working fine. first thing to configure a email client for your emulator.
enter code here