我无法用我的程序读取pdf文件。代码很简单,但遗憾的是它不起作用。提前谢谢你
String path =getActivity().getFilesDir()+"/test.pdf";
File file = new File(path);
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent=Intent.createChooser(target,"Open File");
startActivity(intent);
答案 0 :(得分:0)
以下是有关如何使用Intent选择器打开该文件(test.pdf)的代码:
File file = new File(getActivity().getFilesDir()+"/test.pdf");
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
答案 1 :(得分:0)
答案 2 :(得分:0)
如何打开pdf文件click here for complete code
private void openRenderer(String filePath) {
File file = new File(filePath);
try {
mFileDescriptor = ParcelFileDescriptor.open(file,
ParcelFileDescriptor.MODE_READ_ONLY);
mPdfRenderer = new PdfRenderer(mFileDescriptor);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}