send mail using intent in android

send mail using intent in android

              An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an ActivitybroadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.
                  An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.

Here I have added coding to send email using intent.

It’s a simple step to send email from intent.

1. You can add To, Subject, Cc, and Text to the mail.

public class send_mail extends Activity
{
Button,btn_mail;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
btn_mail=(Button)findViewById(R.id.btn_mail);
btn_mail.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, "");
intent.putExtra(Intent.EXTRA_SUBJECT, "");
intent.putExtra(Intent.EXTRA_TEXT,"" );
try {
startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(second.this,
"There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top