[英]I am downloading pdf's to internal storage but my pdf viewer can not find them
I download a pdf file to internal storage and then programmatically create buttons that take them to an action view. 我将pdf文件下载到内部存储中,然后以编程方式创建将其带到操作视图的按钮。 I can listFiles[] and Toast that they are there but the pdf viewer says file does not exist or file can not be viewed.
我可以在listFiles []和Toast中找到它们,但是pdf查看器显示文件不存在或无法查看文件。
These are the main components of the write to internal storage during download. 这些是下载期间写入内部存储器的主要组成部分。
private File file;
file = new File(mContext.getFilesDir(), filename+".pdf");
// Output stream to write file in internal storage
OutputStream output = new BufferedOutputStream(new FileOutputStream(file));
Then in another activity I get the filenames from the database and create a table with buttons 然后在另一个活动中,我从数据库中获取文件名,并创建带有按钮的表
// ....Inside a for loop .....
Button c3 = new Button(this);
c3.setText("view");
c3.setId(p.getPosterID());
c3.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
File pdfFile = getBaseContext().getFileStreamPath(filename+".pdf");
if (pdfFile.exists()){
Uri path = Uri.fromFile(pdfFile);
//================================================================================
Log.d("path: ", path.toString());
//this will log: file:///data/data/com.myapp.posterviewer/files/5453b54b83b5f.pdf
//================================================================================
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e){
Toast.makeText(ListPosters.this, "No Application Available", Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(ListPosters.this, "The file does not exist", Toast.LENGTH_LONG).show();
}
}
});
Am I generating the path right with Uri path? 我是否使用Uri路径生成路径? I am not able to see the files from windows explorer when in the app folder either.
在应用程序文件夹中时,我也无法从Windows资源管理器中看到文件。 But all my checks say file is exists and I thought that would be in the app root folder.
但是我所有的检查都说该文件存在,我认为那应该在应用程序的根文件夹中。
Internal Storage Only Visible to your Application. 内部存储仅对您的应用程序可见。 The OutSide Application(Pdf Viewer) Cannot Access it.
OutSide应用程序(Pdf查看器)无法访问它。 Save you Pdf file in External Storage and then open it via Pdf Viewer
将Pdf文件保存在外部存储中,然后通过Pdf Viewer打开
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.