使用外部应用

时间:2015-04-22 10:59:44

标签: android pdf android-intent

我想通过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);

显示应用程序选择器,当我点击Adobe PDF时,它不会显示PDF文件。

我做错了什么,或者根本不可能?

2 个答案:

答案 0 :(得分:0)

这对我有用,

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);

答案 1 :(得分:0)

您有两个选择:

  1. 将文件放在PDF查看器应用可以访问的公共存储中
  2. 使用ContentProvider类为该PDF查看器提供对私有文件的访问权。
  3. 请参阅: How to copy files from 'assets' folder to sdcard? http://developer.android.com/guide/topics/providers/content-provider-creating.html