如何使用内部存储器中的其他应用程序读取pdf文件?

时间:2012-04-25 09:01:41

标签: java android pdf

在我的应用程序中,我在内部应用程序文件(数据/数据/包/文件)中创建一个pdf文件我希望这些文件在我使用此代码阅读时可读:

 Uri path = Uri.fromFile(pdfFile); 
 Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
 pdfIntent.setDataAndType(path, "application/pdf");
 pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

我已经阅读了有关使用openOutputStream()方法的内容,但我不知道如何通过它阅读它们。有人可以帮助我吗?

修改

pdfFile -

    File    directory=getFilesDir();
    pdfFile=new File(directory,filename+".pdf"); 

2 个答案:

答案 0 :(得分:1)

将PDF写入内部存储空间时,将MODE_WORLD_READABLE传递给openOutputStream()。从理论上讲,这将允许第三方应用程序读取它。

或者,为此文件实施ContentProvider,例如我在this sample project中演示的文件(此处,将assets/中的PDF复制到内部存储空间中)。

答案 1 :(得分:0)

添加:
pdfFile.setReadable(true,false);