我一直在使用this PDF library,试图获得PDF文件所在位置的路径,但我一直收到错误。这里我漏掉了什么?

查看我的Android设备监视器,我可以在数据库文件夹中看到我的数据库,它也位于assets文件夹中,但我找不到所有的pdf文件?请问他们在哪里?检查下面的图像

感谢朋友们,这是我的错误,我刚刚发现我需要在打开文件之前将文件从资产读取到文件目录中。正在使用下面的代码工作
` private void CopyReadAssets(String fileName) { AssetManager assetManager = this.getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(this.getFilesDir(), fileName);
try
{
in = assetManager.open(fileName);
out = this.openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
Utility.copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e)
{
Log.e("tag", e.getMessage());
}
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
File dir_file = new File(file.getAbsolutePath());
//<-- Get FileType
String mimeType = Utility.getFileMineType(dir_file);
intent.setDataAndType(Uri.fromFile(file), mimeType); //"file://" + getFilesDir() + "/abc.pdf"),"application/pdf"
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if(mimeType.equals("application/pdf")){
Log.e(TAG, Uri.fromFile(file).toString()+" -- "+dir_file);
//mPDFView = new StudentPdfViewer();
// mPDFView.display("Symfony.pdf", false);
//handle it as activity
Intent intent1 = new Intent(this, PdfViewer.class);
intent1.putExtra(Config.COURSE_FILE, fileName);
//intent1.putExtra(SqliteDb.COURSE_NAME, listCategory.get(0).getCategory_name());
//intent1.putExtras(mBundle);
startActivity(intent1);
}else{
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "Unable to load selected Course Material, Please check the Study Studio installation guide to install the required dependency softwares", Toast.LENGTH_LONG).show();
}
}
}`
发布于 2015-08-17 01:18:26
设备上没有“资源文件夹”,设备上也没有“PDF文件所在位置的路径”。
应用程序项目中的assets/文件夹的内容存储在应用程序密钥中。您可以通过AssetManager访问资产,您可以通过在任何方便的Context上调用getAssets()来获得资产,比如Activity。
https://stackoverflow.com/questions/32037793
复制相似问题