2012-10-18 49 views
0
<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" /> 

我有一个包含我的电子邮件信息的测试视图。如何在点击消息时打开默认的电子邮件客户端。Android:单击标签打开电子邮件应用程序

<string name="email">E-mail:[email protected]</string> 

这是我的覆盖方法。

@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     
       } 

      }); 
} 

我应该从这里做什么?

回答

3
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); 
+0

如何将我的文本的值转换为无硬编码 – theJava

+0

t2.getText()。toString(); –

+0

我们是否必须将此活动添加到清单? –

4
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...)); 
2

试试这个代码:

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); 
1

不要忘记设置文本到Android:可点击: “真正的”

+0

它是做什么的。 – theJava

+0

它使文本可点击和集中的动作触摸 –

2

只需使用Linkify在你的TextView,

TextView t2 = (TextView) findViewById(R.id.TextView03); 
t2.setText("E-mail:[email protected]"); 
Linkify.addLinks(t2, Linkify.EMAIL_ADDRESSES); 

为此,您的文字视图会将此电子邮件地址显示为超链接您可以在其上单击并选择相应的提供商以在给定的电子邮件地址上发送电子邮件。

3

我知道它很晚了,但只是想分享一些我发现更容易的东西!如果你是在一个TextView显示电子邮件,然后使用:

<TextView 
... 
android:text="Email: [email protected]" 
android:autoLink="email" 
/> 

这会自动将打开首选的电子邮件应用程序的用户手机上的“要”与上述电子邮件ID预先填写地址。

+0

最佳答案我发现!谢谢! – fabricio

相关问题