21.04.2014 Views

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CURSO ANDROID<br />

94<br />

<br />

<br />

<br />

Agregando funcionalidad<br />

Asociaremos todo el código <strong>de</strong>l envío <strong>de</strong>l email al evento <strong>de</strong> click sobre el botón “Enviar”:<br />

Button btnSend = (Button) findViewById(R.id.btnSend);<br />

btnSend.setOnClickListener(new OnClickListener() {<br />

@Overri<strong>de</strong><br />

public void onClick(View v) {<br />

}<br />

});<br />

Obtenemos primero los elementos <strong>de</strong>l form con los datos el email (<strong>de</strong>stinatario, asunto, cuerpo <strong>de</strong>l mail<br />

y adjunto):<br />

// obtenemos los datos para el envío <strong>de</strong>l correo<br />

EditText etEmail = (EditText) findViewById(R.id.etEmail);<br />

EditText etSubject = (EditText) findViewById(R.id.etSubject);<br />

EditText etBody = (EditText) findViewById(R.id.etBody);<br />

CheckBox chkAttachment = (CheckBox) findViewById(R.id.chkAttachment);<br />

Luego construimos un intent que luego utilizaremos para levantar la Activity para el envío <strong>de</strong>l correo,<br />

este <strong>de</strong>be ser <strong>de</strong>l tipo ACTION_SEND, posteriormente indicamos cuál será el tipo <strong>de</strong> dato a enviar.<br />

// es necesario un intent que levante la actividad <strong>de</strong>seada<br />

Intent itSend = new Intent(android.content.Intent.ACTION_SEND);<br />

// vamos a enviar texto plano a menos que el checkbox esté marcado<br />

itSend.setType(“plain/text”);<br />

Colocamos todos los datos obtenidos <strong>de</strong>l form, incluyendo el posible adjunto en caso <strong>de</strong> que el Check-<br />

Box esté marcado.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!