3

I need to take multiple photos at once using the camera intent. The user will press a button from the application and then the camera application will be used. The user will take multiple photos. When the user returns to the main application, I need these photos to be stored in a separate directory.

As far as I have seen, INTENT_ACTION_STILL_IMAGE_CAMERA is the best intent for this. Is it possible to specify a directory to the camera intent so that the camera stores all the new photos (until the user returns to the main application) to that directory? It is something like specifying a file path to ACTION_IMAGE_CAPTURE using the EXTRA_OUTPUT.

Preetom Saha Arko
  • 2,588
  • 4
  • 21
  • 37

3 Answers3

3

Edit: Misread which intent was in question.

INTENT_ACTION_STILL_IMAGE_CAMERA does not take any arguments; you cannot give it a directory to save images into, or anything else. It's simply designed to launch the default camera app, just like hitting the app's main launch icon.

It's generally used by widgets, the lock screen, or other similar features to launch the camera.

There's also ACTION_IMAGE_CAPTURE, which launches a camera app in a special mode where a single picture is taken and then returned to the requesting app. There, a destination for the file can be provided. But this capture intent is not designed for taking multiple pictures at a time.

Either you need to invoke this intent in a loop, or you need to build your own camera capture activity.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
0

A solution that works for me is save all photo path + name before launch the camera, then compare the lists after take all photos.

But the bigger problem is to read the SD card path, while read internal storage is easy in Android.

UserOfStackOverFlow
  • 108
  • 1
  • 3
  • 14
-1

First, Store the images as an ArrayList and create an ImageAdapter for those images, and in a GridView for instance. Secondly, Set an setOnItemClickListener on the GridView. Thirdly, create an Intent to start your ImageViewActivity (or whatever name you prefer), and then do a intent.putExtra(EXTRA_RES_ID) of those images (ID of the images). Finally, startActivity(intent).

Alternatively, as per developer.android.com,

Here's an example solution in a method that returns a unique file name for a new photo using a date-time stamp:

String mCurrentPhotoPath;

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
        imageFileName,  /* prefix */
        ".jpg",         /* suffix */
        storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

With this method available to create a file for the photo, you can now create and invoke the Intent like this:

static final int REQUEST_TAKE_PHOTO = 1;

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            ...
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                                                  "com.example.android.fileprovider",
                                                  photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

See more here Android Photo Basics

BenJaminSila
  • 593
  • 5
  • 12
  • I do not have any image at first. I get images only after returning from the camera application. How can I store images in an ArrayList before using the intent? – Preetom Saha Arko Jan 11 '18 at 07:39