2

Possible Duplicate:
How to list my app downloads

I created an android app that displays a list of books which users can download them, I made the downloads in the directory /mnt/sdcard/myapp/download

File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/myapp/Download"); 
dir.mkdirs(); 
File file = new File(dir, "filename");

, but I'm wondering how I can list the books that the user has downloaded.

Community
  • 1
  • 1
AliDeV
  • 213
  • 2
  • 10

2 Answers2

1

you could use this code snippet here to get the names of the files. you can store it in an array and then display it with the help of an array adapter in a listview. i hope that helps.

File sdCardRoot = Environment.getExternalStorageDirectory();
File yourDir = new File(sdCardRoot, "yourpath");
for (File f : yourDir.listFiles()) {
if (f.isFile())
    String name = f.getName();
    // make something with the name
}
Anurag Ramdasan
  • 4,189
  • 4
  • 31
  • 53
1

use File.listFiles() to get the content of the directory where you put the files, and use the retern values to fill an adapter (ArrayAdapter, for instance) to use in conjunction with a ListView

Blackbelt
  • 156,034
  • 29
  • 297
  • 305