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

問題は次のとおりです。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 に答える
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");}
          );
于 2013-11-28T18:42:52.823 に答える