我将在我的应用程序中显示pdf,并且pdf必须与应用程序捆绑在一起.
有什么好办法呢?
我已经读过,可以通过将pdf文件添加到res/raw文件夹并从那里读取它来实现这一点,但是当我将pdf文件放在那里时我得到了项目错误.
所以我试着把pdf文件放在项目的资产文件夹中,它没有给出任何错误.
这是我试图显示pdf的方式:
File pdfFile = new File("res/raw/file.pdf");
Uri path = Uri.fromFile(pdfFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Run Code Online (Sandbox Code Playgroud)
任何想法或建议?
提前致谢
我试图在"资产"中获取我的文件夹的名称.我可以使用AssetManager.list()方法通过AssetManager获取文件的名称.但问题是它只返回文件名而不是文件夹名.所以我试图使用listFiles()方法,但我无法访问Assets目录; 我尝试以下方法:
File dir = new File ("file:///android_asset/");
File[] files= dir.listFiles();
Run Code Online (Sandbox Code Playgroud)
但它不起作用:( ...有没有办法让文件夹的名字包含在Assets目录中?
我已经搜索过,没有在应用程序中找到show pdf文件的任何解决方案
关键是我必须显示资产或原始文件夹中的pdf而不是来自网络
我已经在webview中尝试了代码
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setContentDescription("application/pdf");
webview.loadUrl("file:///android_asset/button11.pdf");
Run Code Online (Sandbox Code Playgroud)
但它不是在开玩笑.
我需要提前帮助