Reputation: 15034
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/header"
android:layout_alignLeft="@+id/button1"
android:layout_marginBottom="127dp"
android:text="@string/email"
android:textColor="#000000"
android:textSize="12dp"
android:typeface="sans" />
I have a test view which holds my email information. How do i open an default email client on the click of the message.
<string name="email">E-mail:[email protected]</string>
Here is my Override method.
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView t2 = (TextView) findViewById(R.id.TextView03);
email.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
What should i do from here?
Upvotes: 0
Views: 1937
Reputation: 1461
I know its very late, nevertheless just wanted to share something that I found much easier! If you are displaying email in a textview, then use:
<TextView
...
android:text="Email: [email protected]"
android:autoLink="email"
/>
This automatically will open the preferred email app on the users phone with the "To:" address prefilled with the email ID mentioned above.
Upvotes: 3
Reputation: 3578
Just use Linkify on your TextView,
TextView t2 = (TextView) findViewById(R.id.TextView03);
t2.setText("E-mail:[email protected]");
Linkify.addLinks(t2, Linkify.EMAIL_ADDRESSES);
To do so your text view will show this email address as Hyperlink on which you can click and choose the appropriate provider to send email on given email address.
Upvotes: 2
Reputation: 13785
Try This Code :
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
sendIntent.setData(Uri.parse("[email protected]"));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
sendIntent.setType("plain/text");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Insert text");
startActivity(sendIntent);
Upvotes: 2
Reputation: 144
Intent i= new Intent(android.content.Intent.ACTION_SEND);
i.setType("plain/text");
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
i.putExtra(android.content.Intent.EXTRA_SUBJECT, mySubject);
i.putExtra(android.content.Intent.EXTRA_TEXT, myBodyText);
context.startActivity(Intent.createChooser(i, "Send mail...));
Upvotes: 5
Reputation: 5725
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
sendIntent.setData(Uri.parse("[email protected]"));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "enter subject");
sendIntent.setType("plain/text");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Insert text");
startActivity(sendIntent);
Upvotes: 3