0

我尝试了这个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"); 已显示,但在添加未执行之后,我无法运行 localnotification

4

1 回答 1

0

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

于 2012-11-07T22:37:34.267 回答