在应用程序中打开资产文件pdf

djk*_*djk 5 pdf android

我已经搜索过,没有在应用程序中找到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)

但它不是在开玩笑.

我需要提前帮助

2ba*_*ard 1

这是我用来从文件系统读取pdf的代码,我希望它有帮助!

        File file = new File("/path/to/file");          
        Uri path = Uri.fromFile(file);      
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        try {
             context.startActivity(intent);
            } 
         catch (ActivityNotFoundException e) {
             Toast.makeText(context, "No application available to view PDF", Toast.LENGTH_LONG).show();
            }
Run Code Online (Sandbox Code Playgroud)