Images not being saved when picture is taken by camera app that isn't the stock camera

user2858182

I'm currently trying to save images taken from a phone to its gallery, but the code below only works if I choose the stock camera app when the chooser dialog pops up. Whenever I choose another camera app(e.g., the Google camera), the taken picture doesn't get saved any where.

To make things even stranger, sometimes the picture does show up in its designated directory in the gallery, but after 15 mins or so, the same goes for when I use the stock camera app: the picture will get saved in the default camera shots directory, but takes quite a bit to show up in its designated directory, if it shows up there at all.

// Capturing Camera Image will launch camera app request image capture
void captureImage() {
    //file uri to store image.
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

    // Request camera app to capture image
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

    // start the image capture Intent
    getActivity().startActivityForResult(captureIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);

}
user2858182

It turns out my code was working after all. The pictures were being saved in the new directory, but the problem was that the gallery wasn't being updated, which explains why the photos would randomly appear in the directory later on. Being new to this, it never occurred to me that I would have to update the gallery. I only came to this realization after using ES File Explorer to look through my files. To fix my problem, I just made a new method in my CameraFragment that would call on the media scanner. I called this method from onActivityResult().

Here's the new method, though there's nothing really "new" about it since I ran into the same code on other SO questions:

protected void mediaScan() {
    getActivity().sendBroadcast(
            new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, 
                    Uri.parse(fileUri.toString())));
}

I also don't need to call the package manager and iterate through the apps that could handle the camera intent if I'm not giving the option to use choose a picture from a gallery, so I'm going to remove all that from my question.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Images are not being saved in my camera app

From Dev

picture taken with camera doesn't resize in uiimageview

From Dev

How to show Picture into a activity after taken and saved from custom camera

From Dev

Trying to display the picture in my app that was just taken with the built in camera app

From Dev

Get uri of picture taken by camera

From Dev

Delete picture taken from camera

From Dev

Custom camera shows dark picture preview when photo taken on Nexus

From Dev

Android front camera images are being saved upside down

From Dev

Android front camera images are being saved upside down

From Dev

Android adding image to picture taken with camera

From Dev

Upload a picture taken by the camera to a server with limited size

From Dev

Getting the URL of picture taken by camera with Photos Framework

From Dev

Strange size of picture taken with Android Camera

From Dev

Camera Orientation Change When Picture Taken. Even When Orientation is locked.

From Dev

Uncompressed size of images taken with the camera phonegap

From Dev

Delete all images taken with specific camera

From Dev

Pic won't be saved when front camera used

From Dev

Pictures taken with the camera in my app are upside down

From Dev

while applying overlay images to image which is taken from camera at that time app will terminates in ios

From Dev

UIImagePickerController - Choose saved images in the camera view

From Dev

Android Camera Preview Stretched in Preview, Not After Picture Taken

From Dev

UIImagePickerController shows last picture taken instead of camera input

From Dev

How to set the size and quality of a picture taken with the android camera?

From Dev

Android Camera: Get Picture Uri after the photo is taken

From Dev

Is there a way to specify the file name in advance for the picture taken with the flutter camera plugin?

From Dev

Decode datamatrix out of picture taken by camera2 with zxing

From Dev

Camera2 API picture taken wont show at gallery apps

From Dev

Picture taken with camera as div background image Ionic 3

From Java

Can't see virtual scene images in emulator camera app

Related Related

  1. 1

    Images are not being saved in my camera app

  2. 2

    picture taken with camera doesn't resize in uiimageview

  3. 3

    How to show Picture into a activity after taken and saved from custom camera

  4. 4

    Trying to display the picture in my app that was just taken with the built in camera app

  5. 5

    Get uri of picture taken by camera

  6. 6

    Delete picture taken from camera

  7. 7

    Custom camera shows dark picture preview when photo taken on Nexus

  8. 8

    Android front camera images are being saved upside down

  9. 9

    Android front camera images are being saved upside down

  10. 10

    Android adding image to picture taken with camera

  11. 11

    Upload a picture taken by the camera to a server with limited size

  12. 12

    Getting the URL of picture taken by camera with Photos Framework

  13. 13

    Strange size of picture taken with Android Camera

  14. 14

    Camera Orientation Change When Picture Taken. Even When Orientation is locked.

  15. 15

    Uncompressed size of images taken with the camera phonegap

  16. 16

    Delete all images taken with specific camera

  17. 17

    Pic won't be saved when front camera used

  18. 18

    Pictures taken with the camera in my app are upside down

  19. 19

    while applying overlay images to image which is taken from camera at that time app will terminates in ios

  20. 20

    UIImagePickerController - Choose saved images in the camera view

  21. 21

    Android Camera Preview Stretched in Preview, Not After Picture Taken

  22. 22

    UIImagePickerController shows last picture taken instead of camera input

  23. 23

    How to set the size and quality of a picture taken with the android camera?

  24. 24

    Android Camera: Get Picture Uri after the photo is taken

  25. 25

    Is there a way to specify the file name in advance for the picture taken with the flutter camera plugin?

  26. 26

    Decode datamatrix out of picture taken by camera2 with zxing

  27. 27

    Camera2 API picture taken wont show at gallery apps

  28. 28

    Picture taken with camera as div background image Ionic 3

  29. 29

    Can't see virtual scene images in emulator camera app

HotTag

Archive