Violet Giraffe
Violet Giraffe

Reputation: 33579

Android: what is the default location for storing images?

I'm writing an app that downloads photos from a digital camera. What would be the most appropriate place to save them to? Must be external storage since gigabytes of images are expected.

Upvotes: 3

Views: 12825

Answers (4)

Vijay E
Vijay E

Reputation: 958

External Storage is the best place to store images and the default location is to get it using

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)

If you want to create a folder inside default picture Directory then use below Example code:

File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                + "/Your_folder_name");

Here is method, this is how I am saving Bitmap image to default picture directory:

private String saveImage(Bitmap image) {
        String savedImagePath = null;

        Date d = new Date();
        CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
        String imageFileName = "IMG" + s + count + ".jpg";
        File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                + "/Your_folder_name");
        boolean success = true;
        if (!storageDir.exists()) {
            success = storageDir.mkdirs();
        }
        if (success) {
            File imageFile = new File(storageDir, imageFileName);
            savedImagePath = imageFile.getAbsolutePath();
            try {
                OutputStream fOut = new FileOutputStream(imageFile);
                image.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
                fOut.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

            // Add the image to the system gallery
            //galleryAddPic(savedImagePath);
            //Toast.makeText(mContext, "IMAGE SAVED", Toast.LENGTH_LONG).show();
        }
        return savedImagePath;
    }

Upvotes: 2

Padma Kumar
Padma Kumar

Reputation: 20031

Saving files that should be shared

If you want to save files that are not specific to your application and that should not be deleted when your application is uninstalled, save them to one of the public directories on the external storage. These directories lay at the root of the external storage, such as Music/, Pictures/, Ringtones/, and others.

In API Level 8 or greater, use getExternalStoragePublicDirectory(), passing it the type of public directory you want, such as DIRECTORY_MUSIC, DIRECTORY_PICTURES, DIRECTORY_RINGTONES, or others. This method will create the appropriate directory if necessary. If you're using API Level 7 or lower, use getExternalStorageDirectory() to open a File that represents the root of the external storage, then save your shared files in one of the following directories:

Music/ - Media scanner classifies all media found here as user music.
Podcasts/ - Media scanner classifies all media found here as a podcast.
Ringtones/ - Media scanner classifies all media found here as a ringtone.
Alarms/ - Media scanner classifies all media found here as an alarm sound.
Notifications/ - Media scanner classifies all media found here as a notification sound.
Pictures/ - All photos (excluding those taken with the camera).
Movies/ - All movies (excluding those taken with the camcorder).
Download/ - Miscellaneous downloads.

filesExternal

Upvotes: 4

Charles Munger
Charles Munger

Reputation: 1407

If you want them to be accessible by other applications, just put them in the DCIM folder with the camera's original folder name, (android's is 100ANDROID, other cameras have other ones). Users expect pictures to be stored there, as do other applications.

Upvotes: 1

Caner
Caner

Reputation: 59148

External storage, since you will need lots of space.

Upvotes: 1

Related Questions