简体   繁体   English

我想从资产或Android的原始文件夹中读取pdf文件

[英]I want to read the pdf files from assets or raw folder in android

when im run it im getting this error like "File or folder not found" and " file dosnt exit or can't be opened ".. 当我运行它时,我收到此错误,例如“找不到文件或文件夹”和“文件不存在退出或无法打开”。

This is the code sir.. i want the how to view pdf files from assets or in raw folder sir.. its very imp for my project try to slove my problem sir.. and tell me clearly im new to android sir.. can any one send me code cloerly how to do it.. 这是代码先生..我想要如何从资产或原始文件夹先生中查看pdf文件。.这对我的项目来说非常有意义,请尝试解决我的问题先生..并清楚地告诉我android先生是我的新手..可以任何人都向我发送代码,该怎么做。

enter code here




Uri path = Uri.parse("android.resource:///com.example.pratice/raw/em");
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        try {
            startActivity(intent);
        }
        catch (ActivityNotFoundException e){
            Toast.makeText(this, "NO Viewer", Toast.LENGTH_SHORT).show();
        }

Few, if any, Android PDF viewer apps will honor the android.resource scheme, and there is no Uri scheme for assets. 几乎没有(如果有的话)Android PDF查看器应用程序会采用android.resource方案,并且没有针对资产的Uri方案。

If you want to serve up a PDF file, copy it from assets or a raw resource into internal storage, then use FileProvider to make it available to other apps. 如果要提供PDF文件,请将其从资产或原始资源复制到内部存储中,然后使用FileProvider将其提供给其他应用程序。 Here is a sample application that does this. 这是一个执行此操作的示例应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM