Camera healing

I am trying to start the built-in camera to take a picture, an image that will have the name specified in the action that starts the camera. (code below)

  • When the camera returns, onActivityResult()goes straight to resultCode == Activity.RESULT_CANCELED. Any explanation for this and the solutions would be very helpful.

  • The camera really captures the image, I see it on my SD card using the file viewer, but its name is spare from the camera. How can I get the name of this image that was provided by this activity?

Camera Intent Code

Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = new File("Team image.jpg");
camera.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
camera.putExtra(MediaStore.Images.Media.TITLE, "Team image");
        startActivityForResult(camera, PICTURE_RESULT);

activity result code

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

    if(requestCode == PICTURE_RESULT){
        if(resultCode == Activity.RESULT_OK) {
            if(data!=null){
                Bitmap image = BitmapFactory.decodeFile(data.getExtras().get(MediaStore.Images.Media.TITLE).toString());
                grid.add(image);            
                images.addItem(image);
            }
            if(data==null){
                Toast.makeText(Team_Viewer.this, "no data.", Toast.LENGTH_SHORT).show();
            }
        }
        else if(resultCode == Activity.RESULT_CANCELED) {
            Toast.makeText(Team_Viewer.this, "Picture could not be taken.", Toast.LENGTH_SHORT).show();
        }
}
}
+3
source share
3 answers

, , , , . , SD-, , , . , SD:

Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = new File(Environment.getExternalStorageDirectory(),"TeamImage.jpg");
camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));

startActivityForResult(camera, PICTURE_RESULT);

, ; , , . , , , RESULT_CANCELED. WRITE_EXTERNAL_STORAGE, Camera SD-.

: , MediaStore . , , , Uri MediaStore ContentProvider .

, !

+4

"singleInstance"?

.

, "singleInstance".

+6

Not sure whats wrong with your code, here is what works for me:

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_PIC_REQUEST);

and

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {

            switch (requestCode) {
                case CAMERA_PIC_REQUEST:
                    Bitmap b = (Bitmap) data.getExtras().get("data");
                    if (b != null) {
                        updateThumbnail(b);

                        if (mBitmap != b) {
                            b.recycle();
                        }
                    }
                    break;
}
}
+1
source

All Articles