我正在处理pdf。我正在尝试使用下面的代码从我的应用程序打开 pdf 文件。但我没能打开。
private void openPdf() {
File file = new File("mnt/sdcard.test.pdf");
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(path);
intent.setType("application/pdf");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(), "No application found",
Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
当我在模拟器中尝试此代码时,它显示一个 toast 说“未找到应用程序”(bcoz,通常模拟器中没有安装 pdf 查看应用程序)。当我在设备中测试相同的东西时(特别是在 funbook 选项卡和 sony 选项卡中),它既不显示 Toast 消息,也不打开 pdf 文件。任何人都可以指出我的代码中的错误。事实上,我是第一次使用 pdf。所以我的问题是,
小智 3
尝试LuxuryMode的方法:https ://stackoverflow.com/a/8221594/1500067
我认为您只是缺少 adobe 包 Intent.setPackage("com.adobe.reader");
| 归档时间: |
|
| 查看次数: |
39120 次 |
| 最近记录: |