简体   繁体   中英

Intel XDK save pdf to sdcard filetransfer.download - android

Im buildning an application with intel xdk for android and ios. Im having trouble saving a pdf on the sdcard in android. im able to get the file directory of the unit and my alert text show that im progressing fine. But when i try to save the pdf nothing happens. The application just skip the "fileTransfer.download(...)", no exception, no nothing.

Im probebly missing something but, is filetransfer not supported? been searching but no luck. All ideas are most welcome :o)

/Anders my code:

function download()
{
 window.appRootDirName = "download_test";
            document.addEventListener("deviceready", onDeviceReady, false);

            function onDeviceReady() {
                alert("device is ready");
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
            }

            function fail() {
                alert("failed to get filesystem");
            }

            function gotFS(fileSystem) {
                alert("filesystem got");
                window.fileSystem = fileSystem;
                fileSystem.root.getDirectory(window.appRootDirName, {
                    create: true,
                    exclusive: false
                }, dirReady, fail);
            }

            function dirReady(entry) {
                window.appRootDir = entry;
                alert("application dir is ready");
            }

             var filePathx = window.appRootDir.fullPath + "/test.pdf";
            alert(filePathx);
            try{
            downloadFile = function() {
                    var fileTransfer = new FileTransfer();

                    var url = "http://myserver/file.pdf";
                    var filePath = window.appRootDir.fullPath + "/test.pdf";


                        fileTransfer.download(
                        url, filePath, function(entry) {
                            alert("download complete: " + entry.fullPath);
                        }, function(error) {
                            alert("download error" + error.source);
                        });


            }
            }
            catch(e)
                    {
                        alert("error in filetransfer.download: " + e.message);
                    }
}

You need to include the WRITE_EXTERNAL_STORAGE permissions in the manifest file but the Intel XDK does not provide a UI to enable this permission. I will file a bug for you. http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE

You you should be able to use the Cordova for Android build. There is a PhoneGap Audio example application that I just tested but it does not work. I have filed an bug for the Intel XDK.

You can try a Cordova Android build by doing the following:

Use Intel XDK version 0876:

  • Click Start a New Project
  • Click Work with a Demo
  • Click PhoneGap Audio
  • Click USE THIS DEMO
  • Name your project
  • Click CREATE
  • Click the Develop tab
  • Click 'intelxdk.config.xml'
  • Copy this file for your own project
  • On line 4: change to the name of your project
  • On line 4: change to the name of your username without any symbols or spaces
    • You can check this by going to BUILD tab
    • Click on Cordova for Android BUILD button
    • Click UPLOAD CODE
    • See your Team name: displayed in the right hand 'Cordova Development Build' box above the green Build App Now button
    • Click Close Build Page
    • Click Develop and update your to match the Build screen ie. Line 4: id="usernamewithoutsymbols.audioproject"
    • Note: I will also file a bug for a better UI needed to find the team name
  • Click BUILD tab
  • Click on Cordova for Android BUILD button
  • Click UPLOAD CODE
  • Click Build App Now
  • Click Download build

Install the .apk using adb install .apk

  • Launch the application
  • Tap the red record icon
  • Tap Stop
  • Tap Play

This app should create and save an audio file using Cordova APIs. I just tried this on a 4.0 and Android 2.3 phone and it did not work. Bug filed for you and I will update this post as the issue is tracked.

Documentation can be found at https://software.intel.com/en-us/html5/articles/using-the-cordova-for-android-ios-etc-build-option

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM