Android external sdCard DCIM folder path

痴心易碎 提交于 2019-11-28 08:01:32

问题


I need the DCIM folder path from the external sdCard if it is present. I have observed that this path changes according to the manufacturer of the device ("/storage/extSdCard", "/storage/SdCard", "mnt/storage/extSdCard", ...)

Is there any Android api that would give me the path irrespective of the device?


回答1:


Try out with

String m_path = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DCIM).getAbsolutePath();

For the more details about the storage file structure you check my Blog




回答2:


The answer is here in the API Guide: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

The basic steps are: 1. Check the storage state (if it exists) 2. Get the storage Path 3. Go further in a directory you want 4. Make a folder, read a file, write a file, etc. That part is up to you.

This is taken from the docs:

public File getAlbumStorageDir(String albumName) {
    // Get the directory for the user's public pictures directory.
    File file = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES), albumName);
    if (!file.mkdirs()) {
        Log.e(LOG_TAG, "Directory not created");
    }
    return file;
}



回答3:


Got the same problem using a Samsung device. Using the Google Photos App I was able to identify the real location of my SD-Card storage: "/storage/837D-10EB/DCIM" as opposed to the String given by the Environment framework, which is "/storage/emulated/0/DCIM". I don't know if this is a Samsung "problem" or if it has something to do with Android settings. Anyway, it would be good to know if there is an alternative way of finding the SD-Card Camera storage. I know there has to be one as the Google Photos app also finds those photos without any problem.



来源:https://stackoverflow.com/questions/26751041/android-external-sdcard-dcim-folder-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!