¿Cómo hacer clic en una dirección de correo electrónico?

Tengo un poco de texto en mi aplicación que dice en caso de que necesite ayuda adicional, por favor envíenos un correo electrónico y aquí está la dirección de correo electrónico, bla, bla.

Pero quiero que sean capaces de hacer clic en el enlace de correo electrónico y tener su cliente de correo electrónico abierto. ¿Es eso posible? ¿O es esa mala práctica?

Si es una práctica razonable, ¿cómo se puede hacer?

Esta es una solicitud muy razonable y la clase Linkify convertirá cada dirección de correo electrónico en un enlace apropiado para usted. Simplemente agregue el atributo autoLink a su XML:

 <TextView ... android:autoLink="email" /> 

Puede hacer que su texto haga clic haciendo clic en setOnClickListener en el texto

 textView.setOnClickListener(new View.OnClickListener()); 

Puede abrir el cliente de correo electrónico creando un nuevo intento con ACTION_SEND. Settype, la dirección de correo electrónico y el tema como este:

 Intent emailintent = new Intent(android.content.Intent.ACTION_SEND); emailintent.setType("plain/text"); emailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"[email protected]" }); emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, ""); emailintent.putExtra(android.content.Intent.EXTRA_TEXT,""); startActivity(Intent.createChooser(emailintent, "Send mail...")); 

Necesitas disparar una intención en tu onClickListener :

 Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); // send email as plain text intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" }); intent.putExtra(Intent.EXTRA_SUBJECT, "subject"); intent.putExtra(Intent.EXTRA_TEXT, "mail body"); startActivity(Intent.createChooser(intent, "")); 

La respuesta aceptada puede funcionar para los correos electrónicos, pero si desea detectar diferentes patrones, como correos electrónicos, números de contacto, enlace web y establecer una implementaciones de clic en estos patrones le sugiero que utilice CustomClickableEmailPhoneTextview

Introduzca aquí la descripción de la imagen

Código de ejemplo para usar la biblioteca.

 CustomPartialyClickableTextview customPartialyClickableTextview= (CustomPartialyClickableTextview) findViewById(R.id.textViewCustom); /** * Create Objects For Click Patterns */ ClickPattern email=new ClickPattern(); ClickPattern phone=new ClickPattern(); ClickPattern weblink=new ClickPattern(); /** * set Functionality for what will happen on click of that pattern * In this example pattern is email */ email.setOnClickListener(new ClickPattern.OnClickListener() { @Override public void onClick() { Toast.makeText(MainActivity.this,"email clicked",Toast.LENGTH_LONG).show(); } }); /** * set Functionality for what will happen on click of that pattern * In this example pattern is phone */ phone.setOnClickListener(new ClickPattern.OnClickListener() { @Override public void onClick() { Toast.makeText(MainActivity.this,"phone clicked",Toast.LENGTH_LONG).show(); } }); /** * set Functionality for what will happen on click of that pattern * In this example pattern is weblink */ weblink.setOnClickListener(new ClickPattern.OnClickListener() { @Override public void onClick() { Toast.makeText(MainActivity.this,"website clicked",Toast.LENGTH_LONG).show(); } }); /** * set respective regex string to be used to identify patter */ email.setRegex("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[AZ]{2,4}\\b"); // regex for email phone.setRegex("[1-9][0-9]{9,14}"); // regex for phone number weblink.setRegex("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"); // regex for weblink /** * add click pattern to the custom textview - first parameter is tag for reference second parameter is ClickPattern object */ customPartialyClickableTextview.addClickPattern("email",email); customPartialyClickableTextview.addClickPattern("phone",phone); customPartialyClickableTextview.addClickPattern("weblink",weblink); 
FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.