One activity of my Android application needs to show all the pictures from the phone including sd-card, camera pictures, downloads, etc. How can I perform this with the code? Whether through Intent or some other possible ways? (for instance in google+ application it shows all the pictures from the phone).
-
https://github.com/amirarcane/recent-images – Amirhossein Naghshzan May 26 '16 at 12:41
3 Answers
You need to query the content database using the content resolver
String[] mProjection = {MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA};
mCursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
mProjection,
null,
null,
MediaStore.Images.Media.DEFAULT_SORT_ORDER);
Using the mCursor above you can get the path to the images present on your external storage device.
You will probably require a GridView
and the adapter to the GridView
can use the cursor to get the images one by one.

- 4,225
- 1
- 32
- 41
The best way to do this is by using the MediaStore.Images
content provider. This will show all the images that appear in the Gallery app. However, it will not show hidden images, or images in folders that contain a .nomedia
file. If you want to show those as well, you'll have to recursively scan the filesystem yourself (see File
for that).

- 88,392
- 43
- 149
- 167
-
I don't think you need any. You should just try it and see if you get any security exceptions. – Felix Nov 28 '11 at 11:41
-
An example on this would be helpful. `MediaStore.Images.Media.EXTERNAL_CONTENT_URI` only shows the images in external sd card directly not inside the folders. Please provide and example using recursively scan the filesystem. – Anuj Dec 03 '14 at 06:46
Do you just want to open just the stock Android gallery application?
If you don't, you can always use this MediaStore class. It has all the info you need. http://developer.android.com/reference/android/provider/MediaStore.html

- 9,363
- 2
- 33
- 49
-
1No, not if you're just reading from the sdcard. Writing to the sdcard would be another story, but in your case, you're not doing that, so you're ok. – Stephan Branczyk Nov 28 '11 at 11:50