无法添加localnotification插件到android phonegap应用程序

时间:2012-10-17 10:20:20

标签: android cordova phonegap-plugins

我尝试了这个localnotificationplugin来添加本地通知插件,并按照阅读我的方式处理每一步,虽然我有一些编译错误,但我通过更改alarm = new AlarmHelper(this.ctx);在localnotification.java中解决了new AlarmHelper(cordova.getContext());这是我的localnotification.js

    /*-
 * Phonegap LocalNotification Plugin for Android
 *
 * Created by Daniel van 't Oever 2012 MIT Licensed
 *
 * Usage:
 *
 * plugins.localNotification.add({ date: new Date(), message: 'This is an Android alarm using the statusbar', id: 123 });
 * plugins.localNotification.cancel(123);
 * plugins.localNotification.cancelAll();
 *
 * This interface is similar to the existing iOS LocalNotification plugin created by Greg Allen
 */
if (typeof PhoneGap !== "undefined") {

    /**
     * Empty constructor
     */
    var LocalNotification = function() {
    };

    /**
     * Register a notification message for a specific date / time
     * 
     * @param successCB
     * @param failureCB
     * @param options
     *            Array with arguments. Valid arguments are date, message,
     *            repeatDaily and id
     */
    LocalNotification.prototype.add = function(options) {
        var defaults = {
            date : new Date(),
            message : '',
            ticker : '',
            repeatDaily : false,
            id : ""
        };

        if (options.date) {
            options.date = (options.date.getMonth()) + "/"
                    + (options.date.getDate()) + "/"
                    + (options.date.getFullYear()) + "/"
                    + (options.date.getHours()) + "/"
                    + (options.date.getMinutes());
        }

        for ( var key in defaults) {
            if (typeof options[key] !== "undefined")
                defaults[key] = options[key];
        }

        PhoneGap.exec(null, null, 'LocalNotification', 'add', new Array(
                defaults));
    };

    /**
     * Cancel an existing notification using its original ID.
     * 
     * @param id
     *            The ID that was used when creating the notification using the
     *            'add' method.
     */
    LocalNotification.prototype.cancel = function(notificationId) {
        PhoneGap.exec(null, null, 'LocalNotification', 'cancel', new Array({
            id : notificationId
        }));
    };

    /**
     * Cancel all notifications that were created by your application.
     */
    LocalNotification.prototype.cancelAll = function() {
        PhoneGap
                .exec(null, null, 'LocalNotification', 'cancelAll', new Array());
    };

    /**
     * Register this plugin with phonegap
     */
    PhoneGap.addConstructor(function() {
        alert("constructor called here");
        if (!window.plugins) {
            window.plugins = {};
        }
        window.plugins.localNotification = new LocalNotification();
        alert("localnotification called");
    });
}

调用phonegap构造函数和alert(“localnotification called”);显示但是之后没有执行添加,我无法进行本地通知以运行

1 个答案:

答案 0 :(得分:0)

你在哪里测试它(设备或模拟器)?你知道本地通知不会弹出一个窗口,不是吗? 日志中是否有错误?