Reputation: 1625
When I read from the following two locations, only some of the photos are read:
File appStorage = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File externalStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
Downloaded photos for example are not read. Yet, if I manually open the gallery app, I see all my photos in there.
So how do I read all images that are in the gallery? Basically, where do I look?
EDIT:
I really think my question quite obvious, but for some reason people seem to be stuck on ACTION_PICK
. I am looking for exactly what I say I am looking for above. If I wanted to use ACTION_PICK
, I would use the following code:
public void dispatchGalleryIntent(View view) {
Intent gallery = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(gallery, LOAD_IMAGE_REQUEST_CODE);
}
I don't need my user to pick images from the gallery. No. What I need is for the app itself to load all the images that are in the gallery. I am really not sure how else to say this.
NOTE:
In case more clarification is needed, here is the code I am using to read the files I mention in the OP (i.e., appStorage
and externalStorage
):
void addFiles(final File parent, Set<File> images) {
try {
for (final File file : parent.listFiles()) {
if (!file.isDirectory()) {
images.add(file);
} else {
addFiles(file, images);
}
}
} catch (Exception e) {
}
}
Upvotes: 3
Views: 2927
Reputation: 2434
Try the following
File file = Environment.getExternalStorageDirectory();
You will need to filter the correct extensions such as jpg, png, etc
.
EDIT:
You are correct. Mine is not a great solution as you get all kind of weird images that you don't even know exists on your device. I was just trying to veer people to the right direction so maybe someone with better information can answer you.
On the other hand, on my particular device, all my images are good if I leave out the Android
sub-directory as in /storage/sdcard0/Android/...
. But I can't say this is a final answer as I don't now how other devices would behave. You essentially need to know how the gallery app does it or better yet how to piggyback the gallery app and get everything it sees. Maybe by using some sort of cursor, which I don't know how to use.
Upvotes: 1