Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android PhoneGap在本机应用程序中打开文件。通过Build.phonegap.com构建_Android_Pdf_Cordova_Smartgwt_Phonegap Build - Fatal编程技术网

Android PhoneGap在本机应用程序中打开文件。通过Build.phonegap.com构建

Android PhoneGap在本机应用程序中打开文件。通过Build.phonegap.com构建,android,pdf,cordova,smartgwt,phonegap-build,Android,Pdf,Cordova,Smartgwt,Phonegap Build,首先: 是的,在StackOverflow中有很多解决方案,但在我的例子中没有一个是有效的 我在SmartGWT.mobile中内置了应用程序 我将配置文件和所有需要的文件附加到此构建中,以便为PhoneGap做准备 应用程序是通过build.phonegap.com网站构建的 它在Android 4.1.1上运行得非常好 我想: 将文件下载到本地文件系统它是一个PDF文件-它工作正常使用: var fileTransfer = new FileTransfer(); fileTransfer.

首先:

是的,在StackOverflow中有很多解决方案,但在我的例子中没有一个是有效的

  • 我在SmartGWT.mobile中内置了应用程序
  • 我将配置文件和所有需要的文件附加到此构建中,以便为PhoneGap做准备
  • 应用程序是通过build.phonegap.com网站构建的
  • 它在Android 4.1.1上运行得非常好
  • 我想:

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

    var fileTransfer = new FileTransfer();
    fileTransfer.download(.....
    
  • 在本机应用程序(例如Adobe Reader)中打开PDF,无论是安装在android for PDF上的应用程序-它不工作

    我试过:

    (一)

    (二)

    (三)

    (四) 甚至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构建没有附加类文件,并且找不到WebIntent类,所以它无法工作

    我在config.xml中声明此插件:

        <gap:plugin name="com.borismus.webintent.WebIntent" />
    
    
    
    你知道为什么它不起作用,或者我在做什么吗? 也许你们知道另一种打开文件的方法,就像在本机应用程序中一样,它应该很简单


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

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

    $("#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);
        }
     );
    }
    
    phonegap local plugin add https://github.com/don/FileOpener
    
    然后自动添加所有XML、插件等

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

        <gap:plugin name="com.borismus.webintent.WebIntent" />
    
    $("#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);
        }
     );
    }
    
    phonegap local plugin add https://github.com/don/FileOpener
    
    window.plugins.fileOpener.open( path );