【问题标题】:WebIntent error using PhoneGap 2.4. Reference error: WebIntent is not defined?使用 PhoneGap 2.4 的 WebIntent 错误。参考错误:未定义WebIntent?
【发布时间】:2013-02-28 22:24:22
【问题描述】:

我正在尝试在我的 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”

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

【问题讨论】:

    标签: android cordova webintents


    【解决方案1】:

    问题出在:action: WebIntent.ACTION_VIEW,

    WebIntent 曾经是一个全局变量(糟糕),但现在被包裹在一个闭包中。

    由于您使用的是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")} 
      );
    }
    

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

    【讨论】:

      【解决方案2】:

      即使有修改操作的评论: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");}
                );
      

      【讨论】:

        猜你喜欢
        • 2012-04-17
        • 1970-01-01
        • 2023-03-14
        • 1970-01-01
        • 2014-05-05
        • 2018-12-14
        • 1970-01-01
        相关资源
        最近更新 更多