3

I'm developing an Android app that needs to display images from the default camera folder. My problem is that I do not know how to find what is the internal default storage folder for camera photos.

When I look for it connecting the phone to the PC (it is a Samsung Galaxy S7 without SD card), I see that the pictures are stored in DCIM/Camera. However, this does not work. Doing: files = new File("DCIM/Camera/"); results in the app saying there is nothing there.

How can I find the default internal storage folder for camera photos?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Víctor Martínez
  • 854
  • 2
  • 11
  • 29
  • 1
    Use `getExternalStoragePublicDirectory()` with `DIRECTORY_PICTURES` as described here: https://developer.android.com/guide/topics/data/data-storage.html#filesExternal – Ken Wolf Jun 08 '17 at 15:56
  • https://stackoverflow.com/questions/16993213/how-can-i-find-out-the-camera-images-folder-of-an-android-phone – IAmGroot Jun 08 '17 at 15:59
  • But that is the method used to obtain the default pictures folder for an external storage, isn't it? The problem is that my phone **does not have external storage**. Anyway, I tried it and it does not work... – Víctor Martínez Jun 08 '17 at 16:00
  • **External storage means app public storage** meaning any app can access it. From a user POV that means the device's memory as in the storage cap that came with the device, AND SD card. Internal storage is the app private storage that only a given app can access. The images are not in the internal storage, it is in the shared area and thus external. Yet it isn't in an SD card – Zoe Jun 08 '17 at 16:01

1 Answers1

10

Firstly, you need to understand Android.

  • Internal storage is the app private storage
  • External storage is the publically accessible storage area

External storage in Android means the public storage and means internal storage as in device memory and SD card. Saving to external storage means device internal and SD card, while saving to itnernal storage means app private storage.

So, the images are stored in the external storage or the app public storage where any app can save, load and manage files. The images are publically available and thus not in internal storage by developer definition.

Now, you need the WRITE_EXTERNAL_STORAGE permission and if you target API 23 you also need to request it because it is a dangerous permission.

To access the images, you need to create a new file:

storageDir = new File(
    Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES
    ), 
    "album name here, or remove this part to save or load directly into DCIM"
);

This can be used to save or load images, but remember to index the directory to find the image before loading to prevent IOException

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Thanks for the clarification! Indeed, I didn't know that external storage refers to that :) – Víctor Martínez Jun 08 '17 at 16:02
  • 3
    I understand why, it is hard to understand the difference and know the difference when starting up with Android development because we as users refer to the SD card as external storage and internal device memory as internal storage. In development though, internal storage is app private storage and external is public storage refering to both internal and external storage from the user POV. It is hard to keep track when starting up with Android, but you'll get the hang of it eventually :) – Zoe Jun 08 '17 at 16:06
  • 1
    For people that have the samme issue... Although this answer is very complete and it works perfectly, if you are using an API version greater than API 23, it won't work unless you ask users for the WRITE_STORAGE_PERMISSION. It is not enough to declare it in the Manifest. – Víctor Martínez Jun 10 '17 at 12:53
  • To append to @VíctorMartínez' comment, you have to request on API 23+ **assuming you target API 23 or above**. Targeting and compiling against API 22 means you don't have to request on the appropriate platforms. (But you lose access to newer API's, but I'm not getting into this whole discussion). Read more about the permission system from Android M [here](https://developer.android.com/guide/topics/permissions/requesting.html). I did mention the requesting part in there too :) – Zoe Jun 10 '17 at 13:34