• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the image name inside android sdcard

 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • 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?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • 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: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What went wrong when you tried the code I posted?
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with below



But it doesn't give true for file.isDirectory().
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • 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.
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic