Possible Duplicate:
How to list my app downloads
我创建了一个 Android 应用程序,显示用户可以下载的书籍列表,我在目录/mnt/sdcard/myapp/download 中进行了下载
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/myapp/Download");
dir.mkdirs();
File file = new File(dir, "filename");
,但我想知道如何列出用户已下载的书籍。
最佳答案
您可以在此处使用此代码 fragment 来获取文件的名称。您可以将其存储在数组中,然后借助数组适配器在 ListView 中显示它。我希望这有帮助。
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
}
关于android - 如何显示我的应用程序下载的文件列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9913220/