cordova下载插件在通知栏上显示包名

时间:2015-08-17 01:49:21

标签: javascript android cordova mobile cordova-plugins

我是Cordova和插件的新手.. 我创建了一个webappp,在我的应用程序中我需要从服务器下载文件.. 所以我使用了cordova背景下载插件..我使用的是英特尔xdk ..所以我有插件插件那里.. cordova plugin github

现在..当我下载文件时,在通知栏上显示下载文件..但是它下载时显示插件包名称....但文件保存为其原始名称....这里是我的代码..

var app = {

fileName: "tera hone.mp3",
uriString: "https://api.soundcloud.com/tracks/133667943/stream?client_id=67739332564a7130c3a05f90f2d02d2e",  // 38.3 MB
// Application Constructor
initialize: function() {
    this.bindEvents();
},

downloadFile: function(uriString, targetFile) {

    var lblProgress = document.getElementById('lblProgress');

    var complete = function() {
        lblProgress.innerHTML = 'Done';
    };
    var error = function (err) {
        console.log('Error: ' + err);
        lblProgress.innerHTML = 'Error: ' + err;
    };
    var progress = function(progress) {
        lblProgress.innerHTML = (100 * progress.bytesReceived / progress.totalBytesToReceive) + '%';
    };

    try{

        var downloader = new BackgroundTransfer.BackgroundDownloader();
        // Create a new download operation.
        var download = downloader.createDownload(uriString, targetFile);
        // Start the download and persist the promise to be able to cancel the download.
        app.downloadPromise = download.startAsync().then(complete, error, progress);

    } catch(err) {
        console.log('Error: ' + err);
    }
},

// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);

    document.getElementById('btnStart').addEventListener('click', this.startDownload);
    document.getElementById('btnStop').addEventListener('click', this.stopDownload);
    document.getElementById('btnFileInfo').addEventListener('click', this.getFileInfo);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
    app.receivedEvent('deviceready');

    app.startDownload();
},

startDownload: function () {

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
        fileSystem.root.getFile(app.fileName, { create: true }, function (newFile) {
            app.downloadFile(app.uriString, newFile);
        });
    });
},

stopDownload: function () {
    app.downloadPromise && app.downloadPromise.cancel();
},

getFileInfo: function () {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
        fileSystem.root.getFile(app.fileName, { create: true }, function (fileEntry) {
            fileEntry.file(function (meta) {
                document.getElementById('lblFileInfo').innerHTML =
                    "Modified: " + meta.lastModifiedDate + "<br/>" +
                    "size: " + meta.size;
            });
        }, function(error) {
            document.getElementById('lblFileInfo').innerHTML = "error: " + error;
        });
    });
},

    // Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}

};

这是我从我的html文件中调用的javascript文件..来自cordova插件..

当我停止下载..它停止但应用程序突然每次都崩溃.... 抱歉我的英语不好..

0 个答案:

没有答案