1

我正在尝试在我的 phonegap 应用程序中打开 pdf 和 ppt 文件。我正在使用 phonegap 2.4 和最新版本的 WebIntent 插件。我按照 Webintent上的说明做了

但我仍然收到此错误:

参考错误:未定义 WebIntent

这是我的 html 头部分的一部分:

    <script type="text/javascript" src="js/cordova-2.4.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.2.0.min.js"></script> 
    <script type="text/javascript" src="js/webintent.js"></script>

这是我的 config.xml 文件的一部分

 <cordova>
     ...
   <plugins>
     ...
    <plugin name="Globalization" value="org.apache.cordova.Globalization"/>
    <plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser"/>
    <plugin name="WebIntent" value="com.borismus.webintent.WebIntent"/>
   </plugins>
 </cordova>

这是我使用插件的代码的js部分

    function openFile(filePath){
    window.plugins.webintent.StartActivity({
    action: WebIntent.ACTION_VIEW,
    url: filePath},
    function(){},
    function(){alert("failed to open file")} 
    );
    }

其中 filePath 类似于“file:///mnt/sdcard/file.pdf”

请有人告诉我我做错了什么。PS:我对phonegap和eclipse很陌生。

4

2 回答 2

0

即使有修改操作的评论:WebIntent.ACTION_VIEW with window.plugins.webintent.ACTION_VIEW 对我来说也失败了。

我所做的是直接把 WebIntent.ACTION_VIEW 的值

在 webintent.js 中是:

WebIntent.ACTION_VIEW= "android.intent.action.VIEW";

我的代码示例:

window.plugins.webintent.startActivity({
        action: 'android.intent.action.VIEW',
        type: "application/pdf",
        url: "file:///storage/sdcard0/Mapfre/Documentos/readme.pdf"},
          function() {WL.Logger.debug(">> OK");},
          function() {WL.Logger.debug(">> ERROR");}
          );
于 2013-11-28T18:42:52.823 回答
0

问题出在:action: WebIntent.ACTION_VIEW,

WebIntent曾经是一个全局的 (yuck),但现在被包裹在一个闭包中。

由于您正在使用window.plugins.webintent,您将希望将其更改为:

function openFile(filePath){
  window.plugins.webintent.StartActivity({
    action: window.plugins.webintent.ACTION_VIEW,
    url: filePath},
    function(){},
    function(){alert("failed to open file")} 
  );
}

我已经修改了插件的文档示例。

于 2013-03-13T23:10:41.193 回答