我正在开发一个需要Android Downloader插件的phonegap应用程序:https://github.com/phonegap/phonegap-plugins/tree/master/Android/Downloader

不幸的是,使用最新的cordova(2.2)似乎失败。我花了几个小时尝试升级代码:

downloader.js

cordova.define(
    "cordova/plugin/downloader",
    function(require, exports, module)
    {
        var exec = require("cordova/exec");

        var Downloader = function() {};

        Downloader.prototype.downloadFile = function(fileUrl, params, successCallback, failureCallback)
        {
            // Make params hash optional.
            if (!failureCallback) win = params;

            return exec(
                successCallback,
                failureCallback,
                'Downloader',
                'downloadFile',
                [fileUrl, params]);
        };

        var downloader = new Downloader();
        module.exports = downloader;
    }
);


下载器

package org.apache.cordova.plugins.Downloader;

import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
[more imports...]

public class Downloader extends Plugin
{
etc.


config.xml

<plugins>
<plugin name="App" value="org.apache.cordova.App"/>
[...]
<plugin name="Downloader" value="org.apache.cordova.plugins.Downloader"/>
</plugins>


HTML JS调用

downloader = cordova.require("cordova/plugin/downloader");

downloader.downloadFile(...


该应用程序可以在Eclipse中正常编译,但是在执行下载程序代码时,我得到:找不到ALERT类。日志说:

W / System.err(4035):java.lang.ClassNotFoundException:org.apache.cordova.plugins.Downloader
...
添加插件org.apache.cordova.plugins.Downloader时出错。

您能帮我解决问题吗?

最佳答案

我在js文件中做了一些更改,而不是您自己做,并且一切正常。

function Downloader() {}

Downloader.prototype.downloadFile = function(fileUrl, params, win, fail) {
    //Make params hash optional.
    if (!fail) win = params;
    PhoneGap.exec(win, fail, "Downloader", "downloadFile", [fileUrl, params]);
};

   PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin("downloader", new Downloader());
    PluginManager.addService("Downloader", "com.phonegap.plugins.downloader.Downloader");
});

if(!window.plugins) {
    window.plugins = {};
}
if (!window.plugins.downloader) {
    window.plugins.downloader = new Downloader();
}

10-08 19:09