0

I have a fragment called CameraFragment.java which uses a library called natario1 CameraView. What this fragment allows is, basically, take a picture using the camera. The picture is saved to a path called "Feel". The problem is, every picture has the same name so, when they're saved, if there is already one picture in the directory with the same name of that one that is being saved, it just can't save. How can I manage to give different names to my pictures? This is the code I use which sets the image name to image2:

btnShoot.setOnClickListener(new View.OnClickListener() { 
   @Override
   public void onClick(View view) {
          cmrView.addCameraListener(new CameraListener() {
                  @Override
                  public void onPictureTaken(final byte[] picture) { 
                         super.onPictureTaken(picture);
                          CameraUtils.decodeBitmap(picture, new CameraUtils.BitmapCallback() { 
                                @Override
                                public void onBitmapReady(Bitmap bitmap) {
                                    imgUltimaFoto.setImageBitmap(bitmap); 
                                    imgUltimaFoto.setVisibility(View.VISIBLE);
                                    saveImage(bitmap,"imagem2");
                                }
                            });
                        }
                    });
                    cmrView.capturePicture();
                }
});
Turma RC
  • 71
  • 1
  • 11
  • Possible duplicate of [Test if file exists](https://stackoverflow.com/questions/2786655/test-if-file-exists) – Loebl Jun 29 '18 at 11:14

1 Answers1

1

All you need to to is to add a timestamp to image name.

saveImage(bitmap,"image" + Calendar.getInstance().getTime());

This way, you will always have a different name for each image and it will be organized by date.

Tomash VK
  • 37
  • 4