【问题标题】:PhoneGap open file in native app. Build via build.phonegap.comPhoneGap 在本机应用程序中打开文件。通过 build.phonegap.com 构建
【发布时间】:2013-10-27 06:53:52
【问题描述】:

起初:

是的,StackOverflow 中有很多解决方案,但在我的情况下它们都不起作用。

  1. 我在 SmartGWT.mobile 中构建了应用程序
  2. 我将配置文件和所有需要的文件附加到此版本中,以便为 PhoneGap 做好准备
  3. 应用程序是通过 build.phonegap.com 站点构建的。
  4. 在 Android 4.1.1 上运行良好

我想:

  1. 将文件下载到本地文件系统,它是一个 PDF 文件 - 工作正常 使用:

    var fileTransfer = new FileTransfer();
    fileTransfer.download(.....
    
  2. 在 Android 上安装的原生应用程序(例如 Adob​​e Reader)中打开 PDF 文件 - 它不起作用

    我试过了:

    (1)

    cordova.exec("ChildBrowserCommand.showWebPage", encodeURI(theFile.toURL()) );
    

    (2)

    window.plugins.childBrowser.showWebPage(encodeURI(theFile.toURL()));
    

    (3)

    window.open(encodeURI(theFile.toURL()), '_blank', 'location=yes');
    

    (4) 甚至是 firefox 用于打开 PDF 的 HTML5 插件

所有带有“file://”但前面没有“./”的变体等等。

childBrowser 只显示白屏,每次在前面加上“http://”,window.open - 一样。

我终于找到了像 WebIntent 这样有趣的东西,所以我做到了:

    window.plugins.webintent.startActivity({
          action: window.plugins.webintent.ACTION_VIEW,
          type: "application/pdf",
          url: encodeURI(theFile.toURL().substring(7))},
          function() {},
          function() {alert('Failed to open URL via Android Intent')}
    );

但由于 phonegap-build 没有附加类文件并且它找不到 WebIntent 类,所以它不起作用

我在 config.xml 中声明了这个插件:

    <gap:plugin name="com.borismus.webintent.WebIntent" />

你知道为什么它不工作,或者我在做什么? 也许你知道其他打开文件的方法,就像在原生应用程序中一样,它应该很简单

我只想让我的应用下载并(在本机应用中)为用户显示 PDF。

【问题讨论】:

    标签: android pdf cordova smartgwt phonegap-build


    【解决方案1】:
    $("#page").on('pageshow', function(event, ui) {
     if(event.handled !== true)
        {
        window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
        event.handled = true;
        }
      return false;
    });
    
    function fail() {
        console.log("failed to get filesystem");
    }
    
    function gotFS(fileSystem) {
       console.log("got filesystem");
    
       // save the file system for later access
       console.log(fileSystem.root.fullPath);
       window.rootFS = fileSystem.root;
        downloadImage(url, fileName);
    }
    
    function downloadImage(url, fileName){
       var ft = new FileTransfer();
       ft.download(
        url,
        window.rootFS.fullPath + "/" + fileName,
        function(entry) {
            console.log("download complete: " + entry.fullPath);           
        },
        function(error) {
                console.log("download error" + error.code);
        }
     );
    }
    

    【讨论】:

      【解决方案2】:

      don 的 FileOpener 版本已在我的应用程序 cordova 3.0 上运行

      phonegap local plugin add https://github.com/don/FileOpener
      

      所有的 xmls、插件等都会自动添加。

      在 index.html 上添加了 fileopener.js 然后

      window.plugins.fileOpener.open( path );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-21
        • 2013-08-31
        • 1970-01-01
        • 2018-07-28
        相关资源
        最近更新 更多