【问题标题】:Show local PDF-File with external app使用外部应用程序显示本地 PDF 文件
【发布时间】:2015-04-22 10:59:43
【问题描述】:

我想通过 Share-Intent 使用预安装的 PDF 查看器打开本地 PDF 文件,如下所示:

Uri uri= Uri.parse("file:///android_asset/manual.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType("application/pdf");
startActivity(intent);

显示应用选择器,但当我单击 Adob​​e PDF 时,它不显示 PDF 文件。

是我做错了什么,还是根本不可能?

【问题讨论】:

  • 您保存 pdf 文件的位置。是资产吗?你经过的路径是错误的。无法从该路径打开文件。
  • 是的,我的文件位于资产文件夹中 - 当我检查 uri 时,它看起来很好。
  • 点击此链接stackoverflow.com/questions/17085574/… 从资产中打开 pdf。

标签: android pdf android-intent


【解决方案1】:

这对我有用,

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/directory/"+theNamesOfFiles)),"application/pdf");   
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);

【讨论】:

    【解决方案2】:

    你有两个选择:

    1. 将文件放在 PDF 查看器应用可以访问的公共存储中
    2. 使用ContentProvider 类授予该PDF 查看器访问私人文件的权限。

    见: How to copy files from 'assets' folder to sdcard? http://developer.android.com/guide/topics/providers/content-provider-creating.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多