Search code examples
androidandroid-4.0-ice-cream-sandwichandroid-galleryandroid-camera-intent

Can't see pictures saved in a specific folder


My app uses the phone camera to take pictures and save them in a specific folder. I can't see them with Android Gallery or plugging into my pc, but I can using a file manager app. I found a solution to this: I rename pictures with a file manager app and the I can see them in the gallery.

The code I'm using is:

Intent camera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String dirName = Environment.getExternalStorageDirectory()+"/MyAPP/APP"+ n +".jpg";
Uri uriSavedImage = Uri.fromFile(new File(dirName));
camera.putExtra(MediaStore.EXTRA_OUTPUT,uriSavedImage);
startActivityForResult(camera, 1);
n++;

AndroidManifest:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />

Solution

  • I just needed to add some code to scan the picture and add it to the gallery

    private void addGallery() {
        Intent mediaScanIntent = new Intent(
                Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        String currentPath = Environment.getExternalStorageDirectory()
                + "/MyAPP/APP" + n + ".jpg";
        File f = new File(currentPath);
        Uri contentUri = Uri.fromFile(f);
        mediaScanIntent.setData(contentUri);
        this.sendBroadcast(mediaScanIntent);
    }
    

    I added it in onActivityResult and it works