I'm trying to open the email app from my application and get an error.
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.
The problem is, I set FLAG_ACTIVITY_NEW_TASK. I'm also tried to addFlags
This is my code:
private void mailTo(String mail) {
Intent i = new Intent(Intent.ACTION_SEND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{mail});
try {
context.startActivity(Intent.createChooser(i, ""));
} catch (ActivityNotFoundException ex) {
Toast.makeText(context, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
I must note that, in the same class I have more working Intent Actions.
private void callTo(String number) {
Intent callIntent = new Intent(Intent.ACTION_CALL).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setData(Uri.parse("tel:" + number));
context.startActivity(callIntent);
}
And:
private void smsTo(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}