首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AndroidPdfViewer -无法从Assets文件夹打开PDF文档

AndroidPdfViewer -无法从Assets文件夹打开PDF文档
EN

Stack Overflow用户
提问于 2015-08-17 01:09:46
回答 1查看 658关注 0票数 2

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

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

感谢朋友们,这是我的错误,我刚刚发现我需要在打开文件之前将文件从资产读取到文件目录中。正在使用下面的代码工作

` private void CopyReadAssets(String fileName) { AssetManager assetManager = this.getAssets();

代码语言:javascript
复制
    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();
        }

    }


}

`

EN

回答 1

Stack Overflow用户

发布于 2015-08-17 01:18:26

设备上没有“资源文件夹”,设备上也没有“PDF文件所在位置的路径”。

应用程序项目中的assets/文件夹的内容存储在应用程序密钥中。您可以通过AssetManager访问资产,您可以通过在任何方便的Context上调用getAssets()来获得资产,比如Activity

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32037793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档