0

i'm a newbie in apps development.I want to develop an apps that can save multiple image in sdcard. After I doing several research,on youtube or this page none of them can help me or maybe I can't understand them.For example, android take multiple image with camera . This page just showing that how to save the images in database server, but I need them on sdcard. My problem with my code is, the new image captured will replace the older one. Here is my code.

Button button;
ImageView imageView;
static final int CAM_REQUEST = 1;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.capimg);
    button = (Button) findViewById(R.id.button);
    imageView = (ImageView) findViewById(R.id.image_view);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            Intent camera_intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File file = getFile();
            camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
            startActivityForResult(camera_intent, CAM_REQUEST);


        }
    });


}

private File getFile() {
    File folder = new File("sdcard/UTP_app");
    if (!folder.exists()) {
        folder.mkdir();
    }

    File image_file = new File(folder, "cam_image.jpg");
    if (image_file.exists()) {
        return image_file;
    }
    File image_file2 = new File(folder, "cam_image2.jpg");
    if (image_file2.exists()) {
        return image_file2;
    }
    File image_file3 = new File(folder, "cam_image3.jpg");
    if (image_file3.exists()) {
        return image_file3;

    }


    return folder;
}

I hope I'll improve.

Community
  • 1
  • 1
Zaidi
  • 95
  • 1
  • 10

1 Answers1

1

Just change the filename each time for your camera intent. For example,

private File getFile() {
    File folder = new File("sdcard/UTP_app");
    if (!folder.exists()) {
        folder.mkdir();
    }

    return new File(folder, new Date().getTime()+".jpg");
}
Raiv
  • 5,731
  • 1
  • 33
  • 51
  • I see.So,u are using getTime() method to change each filename. I've never knew that the method exist. I need to learn more. Thanks! for helping me. – Zaidi Feb 15 '16 at 19:38