How to know where on the SD card the images are being stored, DCIM/Camera, DCIM/100MEDIA?

不问归期 提交于 2019-12-21 16:56:35

问题


I have a method in my application which retrieves the last saved image in my DCIM/Camera folder and copies it to another location on the SD card. I've just tested it on another phone and found that it defaults saving to DCIM/100MEDIA. How am I able to get this path?

I ended up writing some code which looped through all the folders in the DCIM folder and retrieved the path of the lastModified() folder.


回答1:


Looks like it is manufacturer dependent. In addition to using methods described in book, it seems also allowing the user to choose/override the default you "discover" would be an important option.

From Pro Android 3: p 579

Unfortunately, there is not a method call to tell you which directory might be used underneath the DCIM directory for Camera pictures. There are a couple of methods though to tell you where the top of the SD card is. The first is Environment.getExternalStorageDirectory() and it returns a File object for the top-level directory for the SD card.

See the following Google books link for full page text: http://books.google.com/books?id=RuN0jb4YASwC&pg=PA579&lpg=PA579

  • other references:

Do all Android phones with a built-in camera use a folder called "DCIM" to store captured images?

http://androidforums.com/android-lounge/5930-definitive-androids-folder-structure.html#post239353




回答2:


Maybe this can help you:

File picDir;            
if (Build.VERSION.SDK_INT > 7)
    picDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
else
    picDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "Pictures/");

Hope this can help. Based on this.



来源:https://stackoverflow.com/questions/8621514/how-to-know-where-on-the-sd-card-the-images-are-being-stored-dcim-camera-dcim

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