英文:
How to get links to all pdf files from removable storage(SD Card) of android in java?
问题
以下是您要翻译的内容:
无法从可移动存储(SD 卡)中获取 PDF 文件。
我已经成功使用以下方法从外部存储中获取了所有 PDF 链接
public String findBooks() {
String pdf = ".pdf";
String epub = ".epub";
File dir = Environment.getExternalStorageDirectory();
Queue<File> toVisit = new PriorityQueue<>();
toVisit.add(dir);
String pdfs = "";
int pdfCount = 0;
if (toVisit.size() != 0) {
while(true){
File file = toVisit.remove();
File[] tmpList = file.listFiles();
int i;
for(i = 0; i < tmpList.length; i++){
if (tmpList[i].isDirectory()) {
toVisit.add(tmpList[i]);
}
else if (tmpList[i].getName().endsWith(pdf) || tmpList[i].getName().endsWith(epub) ){
pdfs += tmpList[i].toString() + ",";
pdfCount += 1;
}
}
if(toVisit.size() == 0){
Toast.makeText(getReactApplicationContext(), "搜索结束:" + String.valueOf(pdfCount), 0).show();
break;
}
}
}
return pdfs;
}
英文:
I am unable to fetch pdf files from removable storage(SD Card).
I have successfully fetched all the links to pdfs in the external storage using the following method
public String findBooks() {
String pdf = ".pdf";
String epub = ".epub";
File dir = Environment.getExternalStorageDirectory();
Queue<File> toVisit = new PriorityQueue<>();
toVisit.add(dir);
String pdfs = "";
int pdfCount = 0;
if (toVisit.size() != 0) {
while(true){
File file = toVisit.remove();
File[] tmpList = file.listFiles();
int i;
for(i = 0; i < tmpList.length; i++){
if (tmpList[i].isDirectory()) {
toVisit.add(tmpList[i]);
}
else if (tmpList[i].getName().endsWith(pdf) || tmpList[i].getName().endsWith(epub) ){
pdfs += tmpList[i].toString() + ",";
pdfCount += 1;
}
}
if(toVisit.size() == 0){
Toast.makeText(getReactApplicationContext(), "End of search: "+ String.valueOf(pdfCount), 0).show();
break;
}
}
}
return pdfs;
}
答案1
得分: 1
我已经成功使用以下方法获取了外部SD卡中所有PDF链接。
我猜我应该能够使用相同的方法从内部存储中获取PDF。
不可以,因为您无法访问内部存储,除了专门为您的应用程序设置的目录之外(例如,Context
上的getFilesDir()
)。
英文:
> I have successfully fetched all the links to pdfs in external SD card using the following method
That code is working with external storage, not removable storage.
> I guess I should be able to use the same method to fetch pdfs from internal storage as well
No, because you have no access to internal storage, other than the directories set aside specifically for your app (e.g., getFilesDir()
on Context
).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论