Question

premier post si gentil :)

Mon problème est que j'ai une classe pour ouvrir ma caméra de téléphone.Cependant, si j'appuie sur le bouton arrière de mon téléphone, l'application s'écrasera.

Y a-t-il un moyen de prévenir cela?peut-être simplement désactiver le bouton arrière?

Toute aide serait appréciée

Ceci est le code que j'appelle pour ouvrir la caméra.

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

Edit: Ce problème se produit également lorsque j'ai un autre bouton pour ouvrir la galerie.L'application vient de se bloquer si le bouton arrière est enfoncé.

    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);
        }
    });

Merci gars

hemm.

Était-ce utile?

La solution

Essayez:

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

et:

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();
     }
    }    
}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top