Search code examples
androidandroid-6.0-marshmallowandroid-sourceandroid-sdcard

Android - When are the default folders (DCIM, Downloads, etc.) in the sdcard created?


I am building a custom Marshmallow Android version, and I would like to add some files to the sdcard on first boot - specifically, I want them to be created at the same time DCIM, Downloads, Ringtones, etc. are being created.

When is the default folder structure created?


Solution

  • While in theory you can find this kind of thing by doing a full text search for a string, that can take a while on a many-gigabyte codebase, so it helps to have some good guesses for where to look.

    It turns out that the default folders are created in MediaProvider.Java located in packages/providers/MediaProvider

    Depending on the specific version of Android the method may be called ensureDefaultFolders() or createDefaultFolders() or something else. For example:

        private static final String[] sDefaultFolderNames = {
            Environment.DIRECTORY_MUSIC,
            Environment.DIRECTORY_PODCASTS,
            Environment.DIRECTORY_RINGTONES,
            Environment.DIRECTORY_ALARMS,
            Environment.DIRECTORY_NOTIFICATIONS,
            Environment.DIRECTORY_PICTURES,
            Environment.DIRECTORY_MOVIES,
            Environment.DIRECTORY_DOWNLOADS,
            Environment.DIRECTORY_DCIM,
        };
        /**
         * Ensure that default folders are created on mounted primary storage
         * devices. We only do this once per volume so we don't annoy the user if
         * deleted manually.
         */
        private void ensureDefaultFolders(DatabaseHelper helper, SQLiteDatabase db)