PhoneGap open file in native app. Build via build.phonegap.com

穿精又带淫゛_ 提交于 2019-12-24 00:17:20

问题


At first:

YES, there are many solutions in StackOverflow, but non of them works in my case.

  1. I got application built in SmartGWT.mobile
  2. I attached config files and all needed files to this build to prepare it for PhoneGap
  3. Application is build via build.phonegap.com site.
  4. It works perfectly fine on Android 4.1.1

I want to:

  1. Download file to local filesystem it is an PDF file - It is working fine using:

    var fileTransfer = new FileTransfer();
    fileTransfer.download(.....
    
  2. Open PDF in native app (for eg. Adobe Reader) whichever is installed on android for PDFs - it is not working:

    I tried:

    (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) even HTML5 plugin for open PDFs by firefox

All variations with "file://" without with "./" at front and so on.

childBrowser shows only white screen, each time adds "http://" at front, window.open - the same.

I finally found something interesting like WebIntent, so i did:

    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')}
    );

but its not working due to fact that phonegap-build not attaching class file and It can not find WebIntent Class

I declare this plugin using in config.xml:

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

Do you know why it is not working, or what I'm doing worng ? Maybe you know other way to open file just like that in native app, it suppose to be simple

I just want my app to download and show (in native app) the PDF for user.


回答1:


don's FileOpener version have worked on my app cordova 3.0

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

all the xmls, plugin, etc are then added automatically.

added fileopener.js on index.html and then

window.plugins.fileOpener.open( path );



回答2:


$("#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);
    }
 );
}


来源:https://stackoverflow.com/questions/19449495/phonegap-open-file-in-native-app-build-via-build-phonegap-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!