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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CURSO ANDROID<br />

48<br />

Agregando código para funcionalidad<br />

Definimos 3 constantes, con dos <strong>de</strong> ellas vamos a i<strong>de</strong>ntificar la acción realizada (tomar una fotografía o<br />

bien seleccionarla <strong>de</strong> la galería) y con la otra estableceremos un nombre para el archivo don<strong>de</strong> escribiremos<br />

la fotografía <strong>de</strong> tamaño completo al tomarla.<br />

private static int TAKE_PICTURE = 1;<br />

private static int SELECT_PICTURE = 2;<br />

private String name = “”;<br />

La forma más sencilla <strong>de</strong> tomar fotografías es utilizar un intent con ACTION_IMAGE_CAPTURE, acción<br />

que pertenece al Media Store 1 y luego sobrecargar el método onActivityResult para realizar<br />

algo con el archivo recibido <strong>de</strong> la cámara. Dentro <strong>de</strong>l método onCreate asignaremos a la variable <strong>de</strong><br />

instancia name y luego vamos a trabajar sobre la acción al click <strong>de</strong>l botón.<br />

Este nombre, inicializado con una llamada a getExternalStorageDirectory() guardará un<br />

archivo en la tarjeta SD <strong>de</strong>l teléfono y el archivo se llamará test.jpg cada vez que grabemos una fotografía<br />

<strong>de</strong> tamaño completo se sobre escribe.<br />

name = Environment.getExternalStorageDirectory() + “/test.jpg”;<br />

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

1 http://<strong>de</strong>veloper.android.com/reference/android/provi<strong>de</strong>r/MediaStore.html

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

Saved successfully!

Ooh no, something went wrong!