【发布时间】:2018-08-01 04:27:48
【问题描述】:
我是 android 新手,我想将下载的 Pdf 文件保存到“DIRECTORY_DOCUMENTS”,因为当我保存到下载文件夹时,它没有在我的应用程序中显示应用程序。 这是代码(当我切换到其他目录并将我的pdf放入其中时它可以工作)。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ListView lv = findViewById(R.id.lv);
lv.setAdapter(new CustomAdapter(MainActivity.this, getPDFs()));
}
private ArrayList<PDFDoc> getPDFs()
{
ArrayList<PDFDoc> pdfDocs = new ArrayList<>();
//TARGET FOLDER
File downloadsFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
PDFDoc pdfDoc;
if (downloadsFolder.exists()) {
//GET ALL FILES IN DOWNLOAD FOLDER
File[] files = downloadsFolder.listFiles();
//LOOP THRU THOSE FILES GETTING NAME AND URI
for (File file : files) {
if (file.getPath().endsWith("pdf")) {
pdfDoc = new PDFDoc();
pdfDoc.setName(file.getName());
pdfDoc.setPath(file.getAbsolutePath());
pdfDocs.add(pdfDoc);
}
}
}
return pdfDocs;
}
}
【问题讨论】:
标签: android-studio directory download-manager