0

Hi I'm looking for a way to save photos from the camera device directly without ask the user to save or not. I'm not implementing the Camera classes or overriding it. I'm simply using this code above. Do you have any ideas on how to do it?

TextReader tr = new TextReader(TextReader.DIRECTORY_EMPRESAS);
String path = TextReader.PARENT_PATH + "/" + TextReader.DIRECTORY_IMAGES;
String dataAtual = new SimpleDateFormat("yyMMddHHmmss").format(new Date());

if(tr.verificaDiretorios(path)){
    String pictureName = dataAtual + DADOS.get(0) + ".jpg";
    File pathEmpresa = new File(path + "/" + TextReader.FILE_NAME);
    File imageFile;

    if(pathEmpresa.exists()){
         imageFile = new File(pathEmpresa, pictureName);        
         Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
         i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
         //startActivity(i);
         startActivityForResult(i, 2);

    }else{
        if(pathEmpresa.mkdir()){        
            imageFile = new File(pathEmpresa, pictureName);     
            Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
            //startActivity(i);
            startActivityForResult(i, 2);
        }else{
            throw new IllegalStateException("Não foi possivel criar o diretorio: " +         pathEmpresa);
        }
}    
Dennis
  • 1
  • 1

1 Answers1

0

You can't do that with an Intent. You need to use the Camera class.

Refer to the documentation:

http://developer.android.com/reference/android/hardware/Camera.html


Quick Example:

Camera camera = camera.open();
camera.takePicture(null, null, new Camera.PictureCallback() {
    public void onPictureTaken(byte[] data, Camera camera) {
        if (data != null) {
            Bitmap picture = BitmapFactory.decodeByteArray(data);
            File f = new File(Environment.getExternalStorageDirectory(), "mydir");
            f.mkdirs();//Grab file directory
            f = new File(f, "mypicturefilename"); //Grab picture file location
            BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f));
            picture.compress(CompressFormat.JPEG, os);//Write image to file
            picture.recycle(); //Clean up
        }
    }
});
Zaid Daghestani
  • 8,555
  • 3
  • 34
  • 44
  • Thanks @Zed Scio. Do you know which methods to override from Camera class should I implement to save it directly? – Dennis May 22 '13 at 17:16
  • I'll do some customize in my software later on tests, then I'll use your example. Thanks – Dennis May 23 '13 at 16:24