有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android:单击标签打开电子邮件应用程序

<TextView
    安卓:id="@+id/TextView03"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:layout_above="@+id/header"
    安卓:layout_alignLeft="@+id/button1"
    安卓:layout_marginBottom="127dp"
    安卓:text="@string/email"
    安卓:textColor="#000000"
    安卓:textSize="12dp"
    安卓:typeface="sans" />

我有一个测试视图保存我的电子邮件信息。如何在单击邮件时打开默认的电子邮件客户端

<string name="email">E-mail:email@gmail.com</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                
                 }

           });
}

从这里我该怎么办


共 (6) 个答案

  1. # 1 楼答案

    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@gmail.com" });
    sendIntent.setData(Uri.parse("email@gmail.com"));
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "enter subject");
    sendIntent.setType("plain/text");
    sendIntent.putExtra(Intent.EXTRA_TEXT, "Insert text");
    startActivity(sendIntent);
    
  2. # 2 楼答案

    我知道已经很晚了,不过我只是想和大家分享一些我觉得容易得多的东西!如果您在文本视图中显示电子邮件,请使用:

    <TextView
    ...
    android:text="Email: username@gmail.com"
    android:autoLink="email"
    />
    

    这将自动在用户手机上打开首选的电子邮件应用程序,并在“收件人:”地址前填入上述电子邮件ID

  3. # 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[] { "demo@gmail.com" });
    sendIntent.setData(Uri.parse("demo@gmail.com"));
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    sendIntent.setType("plain/text");
    sendIntent.putExtra(Intent.EXTRA_TEXT, "Insert text");
    startActivity(sendIntent);
    
  4. # 4 楼答案

    Intent i= new Intent(android.content.Intent.ACTION_SEND);
    i.setType("plain/text");
    i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"email@email.com"});
    i.putExtra(android.content.Intent.EXTRA_SUBJECT, mySubject);
    i.putExtra(android.content.Intent.EXTRA_TEXT, myBodyText); 
    context.startActivity(Intent.createChooser(i, "Send mail...));
    
  5. # 5 楼答案

    只需在TextView上使用Linkify

    TextView t2 = (TextView) findViewById(R.id.TextView03);
    t2.setText("E-mail:email@gmail.com");
    Linkify.addLinks(t2, Linkify.EMAIL_ADDRESSES);
    

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

  6. # 6 楼答案

    别忘了将文本设置为android:clickable:“true”