2013-02-28 56 views
1

我想在我的phonegap应用程序中打开pdf和ppt文件。我正在使用phonegap 2.4和最新版本的WebIntent插件。我所讲述的 Webintent使用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是一样的东西“文件:///mnt/sdcard/file.pdf”

请有人告诉我什么我做错了吗? 个人简历:我对手机和日食相当陌生。

+0

我面临着同样的问题,试图甚至运行github页面上的示例代码来启动谷歌地图 – KamalSalem 2013-03-02 07:14:08

回答

0

的问题是在: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")} 
); 
} 

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

0

即使有修改操作的评论:带有window.plugins.webintent.ACTION_VIEW的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");} 
     );