Pregunta

Primera publicación, así que sé agradable :)

Mi problema es que tengo una clase para abrir la cámara de mi teléfono.Sin embargo, si presiono el botón Atrás en mi teléfono, la aplicación se bloqueará.

¿Hay alguna manera de prevenir esto?Tal vez simplemente deshabilita el botón Atrás?

Cualquier ayuda sería apreciada

Este es el código que llamo para abrir la cámara.

    btnpicture.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityIfNeeded(cameraIntent, CAMERA_REQUEST);
        }
    });

Editar: Este problema también ocurre cuando tengo otro botón para abrir la galería.La aplicación simplemente se estrelló si se presiona el botón Atrás.

    btnsdpic.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent gallery = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
            startActivityIfNeeded(gallery, SELECT_IMAGE);
        }
    });

gracias chicos

doem.

¿Fue útil?

Solución

intento:

 Intent gallery = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
 startActivityForResult(camera, SELECT_IMAGE);

y:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

     if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
       if (resultCode == RESULT_OK) {
        Toast.makeText(this, "Image Caputred", Toast.LENGTH_SHORT).show();
     } else if (resultCode == RESULT_CANCELED) {
        Toast.makeText(this, "Image was not Caputred", Toast.LENGTH_SHORT).show();
     } else {
        Toast.makeText(this, "Image was not Caputred", Toast.LENGTH_SHORT).show();
     }
    }    
}

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top