android phonegap 下载器插件 2.2

标签 android cordova plugins

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

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

下载器.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;
    }
);

下载器.java

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.

配置文件

<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 中编译良好,但在执行下载程序代码时我得到:未找到警报类。 logcat 说:

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

关于android phonegap 下载器插件 2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13413968/

相关文章:

jakarta-ee - Java EE 插件框架

java - 更改对话框微调器的弹出背景颜色

android - RecyclerView 查看项目

cordova - 如何知道设备的媒体音量是静音还是很低

javascript - 阻止 Ionic App 中的导航

xslt - 是否有类似 Ctags 的工具用于在 Vim 中浏览/导航 XSLT 代码?

eclipse - 在 SWT 插件中打包 GDAL JAVA 绑定(bind)和 native 库

android - SSL 主机名匹配如何在 JWS 上工作?

Android - sp出了什么问题?

html - 滚动条出现在滑动菜单旁边