'why email intent in not working in android physical device? [closed]
btnSend.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view) {
String to = editEmailid.getText().toString();
String subject = editSub.getText().toString();
String message = editMessage.getText().toString();
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
else {
Toast.makeText(MainActivity.this, "No app is installed", Toast.LENGTH_SHORT).show();
}
}
Here is the output :
email intent not working
Solution 1:[1]
You should use Intent.ACTION_SEND instead of Intent.ACTION_SENDTO
so here is how you can send email from intent ->
String to=editTextTo.getText().toString();
String subject=editTextSubject.getText().toString();
String message=editTextMessage.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
//need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vishal Beep |

