【问题标题】:How to read a pdf file using other App from internal memory?如何使用其他应用程序从内存中读取 pdf 文件?
【发布时间】:2012-04-25 09:01:41
【问题描述】:

在我的应用程序中,我正在内部应用程序文件(数据/数据/包/文件)中创建一个 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() 方法的信息,但我不知道如何通过此阅读它们。有人可以帮我吗?

编辑

pdf文件--

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

【问题讨论】:

  • 你的pdfFile字符串包含什么?
  • @Pallavi - 文件目录=getFilesDir(); pdfFile=new File(目录,文件名+".pdf");
  • what does your pdfFile string contain? 表示值,当您将其写入 LogCat 或其他地方时...pdfFile=/mnt/data/... pdfFile 变量的值是什么?

标签: java android pdf


【解决方案1】:

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

或者,为此文件实现ContentProvider,例如我在this sample project 中演示的那个(这里,将PDF 从assets/ 复制到内部存储中)。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多