Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to get the image name inside android sdcard

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to show all images inside image folder in sdcard. How to get the all image names which are in the image folder inside sdcard in Android phone?
 
Rancher
Posts: 43027
76
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My device doesn't have an "image" directory as such - images from photo apps end up mostly in directory called "DCIM", and other apps use various directories of their own. You can use new File(Environment.getExternalStorageDirectory() + "/DCIM") and then do a listFiles() on that. You'll need to do that recursively as you encounter subdirectories, and also look at the file extension in case there are other files in there as well.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually i created folder inside the sdcard and put all images to it.So i need to get all of the image path as a array to view in my application could you please provide me an example?
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What went wrong when you tried the code I posted?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried with below



But it doesn't give true for file.isDirectory().
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can't really speculate, because much important information is left out, like what PATH_SD_CARD is, what "file.mkdirs()" returns, why you are calling mkdirs in the first place since the directory already exists, what happens if you call listFiles without the isDirectory check etc. You can use an app like FileManager to explore files on a device, and, as usual, you should experiment with the code much more than you seem to be doing.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I change the code to below



now it gives me null pointer in listFile = file.listFiles(); line.I don't know why it gives me nullpointer exception

The above mention folder is is already there in sdcard.Also there are some images.Then why it doesn't give me the list of images?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic