By using this code i am able to get the gmail compose page directly, but i want to send this mail directly with out coming on gmail page. means when i click on my send button of activity it should directly send the mail to the perticular reciept with out goind on gmail compose page.
protected void sendEmail() {
String[] recipients = { recieverId.getText().toString() };
Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, recipients);
email.putExtra(Intent.EXTRA_SUBJECT, mailSubject.getText().toString());
email.putExtra(Intent.EXTRA_TEXT, mailBody.getText().toString());
final PackageManager pm = getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(email, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") ||
info.activityInfo.name.toLowerCase().contains("gmail"))
best = info;
if (best != null)
email.setClassName(best.activityInfo.packageName, best.activityInfo.name);
try {
startActivity(email);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getApplicationContext(),
"No email client installed.", Toast.LENGTH_LONG).show();
}
}