0

I am currently trying to create an app which when taking a picture using the camera, when saving the image, it saves to a specific folder location and if the folder doesn't currently exist on the phone, it creates the folder and saves the file to that location. My code does not currently work, although I have tried. Could you please look at my code and advise me on what I need to do.

Here is the code:

else if(v==camera){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        File newDirectory = new File(Environment.getExternalStorageDirectory() + "App_Pictures/");
        String filename = new String("image1.jpeg");
        File outputFile = new File(newDirectory, filename);
        outputFile.mkdirs();

        startActivity(intent);
        }
James Meade
  • 1,147
  • 5
  • 22
  • 46

1 Answers1

0

It looks like you're trying to get an external app to take a picture for you. If this is the case, you need to use startActivityForResult, not startActivity, because you want to receive the resulting photo. Then you will receive the result in the onActivityResult method of your activity. This process is described in detail here.

If you actually want your own app to take the picture, instead of an external app, you'll need to use a completely different approach. Here is an app that starts recording a video right when it is launched, and saves it to a directory on the SD card, so perhaps it's a useful starting point if you want to do it this way.

Community
  • 1
  • 1
oakes
  • 743
  • 5
  • 12