查看以下网站: https://github.com/jblough/Android-Pdf-Viewer-Library
他列出了以下代码:
Intent intent = new Intent(this, YourPdfViewerActivity.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "PATH TO PDF GOES HERE");
startActivity(intent);
该路径是什么以及我将PDF文件放在何处?
我已将测试PDF文件放在assests文件夹res / raw中。从数据/数据/项目中的ddms以及libs文件夹中推送文件。我尝试了以下但我仍然找不到文件:
String path = Environment.getExternalStorageDirectory().getPath();
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "test.pdf";
String path = "android.resource://com.example.test3/raw/test.pdf";
String path = "file:///android_assets/test.pdf";
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.pdf";
答案 0 :(得分:0)
final File cacheDir = context.getDir("cache", 0);
if(!cacheDir.exists()) cacheDir.mkdirs();
final File fileContent = new File(cacheDir, "test1.pdf");
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test1.pdf";
path = fileContent.getPath();
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
第一次,它创建了该文件夹,然后我将文件放在该文件夹中并再次运行它,它能够找到该文件。从ddms放置文件。由Selvin回答。
答案 1 :(得分:0)
最简单的,对我有用:
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "pdfName.pdf");
String path = f.getPath();
Intent intent = new Intent(this, BulaActivity.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);