Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing internal storage in Android

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?

like image 578
Víctor Martínez Avatar asked Jun 11 '26 06:06

Víctor Martínez


1 Answers

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

like image 78
Zoe stands with Ukraine Avatar answered Jun 17 '26 05:06

Zoe stands with Ukraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!