0

查看以下网站: 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 文件的位置?

我在assets文件夹res/raw中放置了一个测试PDF文件。从数据/数据/项目中的 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";
4

2 回答 2

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 放置文件。塞尔文回答。

于 2013-11-06T17:37:50.570 回答
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);
于 2014-05-06T19:33:53.847 回答