在应用程序中打开资产文件pdf [英] Open asset file pdf in application

查看:98
本文介绍了在应用程序中打开资产文件pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题的关键是我必须展示从资产或网络文件夹中的原始PDF不是

The point is i have to show pdf from asset or raw folder not from web

我已经尝试在网页视图与code

I have already tried in webview with code

    WebView webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setContentDescription("application/pdf");
    webview.loadUrl("file:///android_asset/button11.pdf");

但它不是沃金。

我需要,帮助
在此先感谢

i need help on that thanks in advance

推荐答案

这是code我使用读取文件系统的一个PDF,我希望它能帮助!

This is the code I use to read a pdf from the filesystem, I hope it helps!

        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();
            }

这篇关于在应用程序中打开资产文件pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆