1

I am trying to open pdf and ppt files in my phonegap application. i am using phonegap 2.4 and the latest version of WebIntent plugin. I did as told on Webintent

but i still get this error:

Reference error: WebIntent is not defined

here is part of my html head section:

    <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>

here is part of my config.xml file

 <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>

here is js portion of the code where i use the plugin

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

where filePath is something like "file:///mnt/sdcard/file.pdf"

Please someone tell me what am I doing wrong. P.S.: I am pretty new to phonegap and eclipse.

Community
  • 1
  • 1

2 Answers2

0

The problem is in: action: WebIntent.ACTION_VIEW,

WebIntent used to be a global (yuck), but is now wrapped in a closure.

Since you are using window.plugins.webintent you will want to change it to something like:

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

I have amended the plugin's documentation examples.

Devgeeks
  • 5,659
  • 4
  • 28
  • 35
0

Even with the comment of modify action: WebIntent.ACTION_VIEW with window.plugins.webintent.ACTION_VIEW failed to me.

What I did was directly put the value of WebIntent.ACTION_VIEW

In the webintent.js it is:

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

My code example:

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");}
          );
Keith
  • 20,636
  • 11
  • 84
  • 125
Jxadro
  • 1,497
  • 2
  • 16
  • 36