【问题标题】:Unable to open local pdf file to webview for android using Appcelerator无法使用 Appcelerator 将本地 pdf 文件打开到 android 的 webview
【发布时间】:2014-08-25 07:36:41
【问题描述】:

我在名为“DocFile”的文件夹中保留了一个 pdf 文件“test.pdf”,并将该文件放入 android 的 asses 文件夹中。

现在,当我尝试在 webview 上显示该 pdf 时,它没有显示任何内容(除了一个空白的 webview)。

app/assets/android/DocFile/test.pdf

在控制器上

myWebView.url = '/DocFile/test.pdf';

但同样的代码适用于 IOS。 请提出建议。

【问题讨论】:

    标签: android pdf webview appcelerator


    【解决方案1】:

    webview 不会显示您的 pdf。同样的问题我已经面临很久了,只需使用下面的代码

    File file = new File("/sdcard/sample.pdf");
    
                            if (file.exists()) {
                                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 {
                                    startActivity(intent);
                                } catch (ActivityNotFoundException e) {
                                    Toast.makeText(
                                            sample.this,
                                            "No Application Available to View PDF",
                                            Toast.LENGTH_SHORT).show();
                                }
    

    【讨论】:

    • 我正在使用此代码,但在 intent.setDataAndType(path, "application/pdf");请告诉我我可以在变量路径中添加什么
    猜你喜欢
    • 2021-05-01
    • 2013-07-25
    • 2012-07-21
    • 1970-01-01
    • 2018-08-19
    • 2023-04-02
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多