Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Camera Intent woes

Hope someone may give some pointers (or an out right answer)... Simple app, take an image using the built-in camera app, save the image to a separate application. Be done.

Problem: The camera application saves the image in the default app location (/mnt/sdcard/external_sd/DCIM/Camera) as well as my custom path (in code below). Both files are exactly the same except for the file name. The external_sd file (the one I want gone) is saved with dashes (-) vs my custom file path saved with underscores. File sizes are exactly the same.

How can I stop this double image issue? Is there an extra intent option I'm missing? Or am I doing this completely wrong, missing something? I'm using a Galaxy S Vibrant.

Code snippet:

private static Uri _outputFileUri;
private static File _file;
private ImageView _image;
private SimpleDateFormat _simpleDateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); 


    _takePicture = (Button) findViewById(R.id.takePicture);
    _takePicture.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            _intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);          

            _file = new File(Environment.getExternalStorageDirectory() +
                            "/Android/data/my own folder/files/",
                             _simpleDateFormat.format(new Date()).toString() + 
                             ".jpg");

            _outputFileUri = Uri.fromFile(_file);

            _intent.putExtra(MediaStore.EXTRA_OUTPUT, _outputFileUri);
            startActivityForResult(_intent, CAMERA_ACTIVITY);
        }
    });   


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

    if (resultCode == RESULT_CANCELED) {
        Toast.makeText(this, "Activity cancelled", Toast.LENGTH_LONG).show();
        return;
    }

    switch (requestCode) {  

        case CAMERA_ACTIVITY: 

            if (resultCode == RESULT_OK) {

                try{
                    Bitmap b = MediaStore.Images.Media.getBitmap(getContentResolver(), _outputFileUri);
                    _image.setImageBitmap(b);
                    _image.invalidate();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
            break;
    }
}
like image 621
Steve Avatar asked Mar 12 '26 22:03

Steve


1 Answers

This is device-dependent behavior. My observation is that HTC devices do not have this duplication problem, but Samsung devices do.

like image 114
John Roberts Avatar answered Mar 14 '26 12:03

John Roberts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!