background information
I have been writing a backup photos service, which needs to get all photo absolute paths from Android external storage (like photos stored in 'DCIM' directory and its subdirectores) and upload them to remote server. The problem is how to get all validate photo absolute paths from Android device. Since there is a vast majority of Android devices, it`s tough to ensure the get-photo-absolute-path algorithm to successfully reach all validate photos Gallery directory and traverse all photos paths inside of it.
Now my app only supports uploading photos from primary external storage (not the secondary external storage, like removable SD card). That`s to say.
- if the device only has one emulated external storage (on-board flash), camera upload service can scan photo paths on it correctly.
- if the device only has a removable storage (like SD card), camera upload service can scan photo paths correctly as well.
the algorithm above scans photo paths from primary external storage which works correctly. But when it comes to
- if the device both has a emulated external storage and a removable storage, camera upload service only scans photo paths on the emulated external storage (primary storage), but a majority of users save their photos to the 16G or bigger size removable SD card (secondary storage) which will be ignored by my app, that`s the problem. see the complete issue here.
Code implementation
To get absolute photo path from internal storage, I hard coded an "external directory list",
String[] paths = {
"/DCIM",
"/DCIM/Camera",
"/DCIM/100MEDIA",
// Many Samsung phones mount the external sd card to /sdcard/external_sd
"/external_sd/DCIM",
"/external_sd/DCIM/Camera",
"/external_sd/DCIM/100MEDIA"
};
and combined the absolute path like
String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + path;
I know that`s not the best practice, that`s why ask for help. BTW, see the complete external directory list
Question
To get absolute photo paths from Android storage
- check if external storage mounted, then scan photos from internal storage by default. This can fit a majority of getting photo path requirements, see the complete implementation here
- let user choose a specific directory to upload photos from SD card (if mounted one)
So I wonder if the proposal above is right or not?
Any comments or reference will be greatly appreciated.
EDIT Different manufacturers set their SD card mounted point differently, there is no regular rules for that, it almost impossible (or say, bad practice) to scan and upload photos by the app in the background automatically. To get photos path from SD card, the practical way I think is to only scan root directories, then shows such directories in a file browser window to let user choose a specific gallery directory and persist the path locally instead of scanning by the app itself. Because it`s error prone to scan photos directives automatically on SD card.