Android – get the path of DCIM folder on primary storage and secondary storage

I'm writing an application that should upload photos taken by the camera, which are stored in the DCIM / camera folder of the memory and SD card

This means that all available storage must be checked for any images before each upload

I use environment.getexternalstoragepublicdirectory (environment. Directory_dcim) to access main memory, which can be SD card or internal memory (depending on the device)

From the document: "note: don't confuse the word" external "here. This directory can be better regarded as media / shared storage. It is a file system that can hold a relatively large amount of data and share applications in all files (permissions are not enforced) Traditionally, this is an SD card, but it can also be implemented as built-in storage in a device different from the protected internal storage, and can be installed on the computer as a file system

My question is how to access the auxiliary memory without hard coding the path to check whether there are images in the DCIM / camera folder. Because the SD card may simulate in different paths, it cannot work normally

resolvent:

Try file [] adirarray = contextcompat.getexternalfilesdirs (context, null);

see http://developer.android.com/reference/android/support/v4/content/ContextCompat.html#getExternalFilesDirs (android.content.Context,java.lang.String)

Remember, external storage (SD card) is not simulated, and all users can see all paths. The above (if it returns non null) returns the root path (file) of each installed external storage. So if adirarray. Length > 1, then the following content provides you with the DCIM path you are looking for on removable storage

File aextdcimdir = new file (adirarray [1], environment. Directory_dcim);

Maybe in your case, you want to check whether environment.directory exists in adirarray [0], adirarray [1],... (all files returned in the array)_ DCIM.

Note that environment.getexternalstoragepublicdirectory (environment. Directory_dcim) returns the same content as the new file (adirarray [0], environment. Directory_dcim)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>