Cordova – Phase “in the PhoneGap application

I am currently trying to use the PhoneGap LocalNotification plugin,
to use Android 4.1 with Cordova 2.0.0 and Sketcha (UI library).

Update #2 20/9/12: I used Bozzzi’s code and fixed some problems:

>added}) to the end of localnotification.js (syntax error).
>cordova .define(“cordova / plugin / LocalNotification”, function (require, exports, module)) is changed to:
cordova.define(“cordova / plugin / LocalNotification”, function (require, exports, module),
So the module name will match this function (before the module is not found):

window.plugins.LocalNotification =
cordova.require(“cordova/plugin /LocalNotification”);

>Change this:

if (!window.plugins) {
window. plugins = {};
}
else if (!window.plugins.LocalNotification) {
window.plugins.LocalNotification = cordova.require(“cordova/plugin/LocalNotification”);
}< /p>

This:

if (!window.plugins) {
window.plugins = {};
}

if (!window.plugins.LocalNotification) {
window.plugins.LocalNotificat ion = cordova.require("cordova/plugin/LocalNotification");
}

Before this change, if window.plugins cannot be found, it will be created, but window.plugins. LocalNotification will not.

After completing all these fixes, I received this error:

06001

< p>For some reason, cordova.require(“cordova/plugins/LocalNotification”) does not set the window.plugins.LocalNotification value and it has been undefined.
This is my updated index.html (update #2):





AndroidSencha











Loading , Please wait..





< /html>

This is my repaired localnotificaiton.js (update #2):

cordova.define("cordova/plugin/LocalNotification" , function(require, exports, module) {

var exec = require("cordova/exec");
var LocalNotification = function () {};

LocalNotification.prototype.add = function(options) {
var defaults = {
date: new Date(),
message:'',
ticker:'',< br /> repeatDaily: false,
id: ""
};
if (options.date) {
options.date = (options.date.getMonth()) + "/" + (options.date.getDate()) + "/"
+ (options.date.getFullYear()) + "/" + (options.date.getHours()) + "/"< br /> + (options.date.getMinutes());
}

for (var key in defaults) {
if (typeof options[key] !== "undefined")
defaults[key] = options[key];
}
< br /> cordova.exec(null, null, "LocalNotification", "add", new Array(defaults));
};

LocalNotification.prototype.cancel = function(notificationId) {
cordova.exec(null, null,'LocalNotification','cancel', new Array({
id: notificationId
}));
};

LocalNotification.prototype.cancelAll = function() {
cordova.exec(null, null,'LocalNotification','cancelAll', new Array());
};


var LocalNotification = new LocalNotification();
module.exports = LocalNotification
});

Update #1: I have added the plugin to plugins In the .xml file:


...

...

I have completed the steps mentioned here and replaced the ones in here The mentioned cracked java expression.

Unfortunately, when I run the application, I receive the following error (in the emulator and device):

p>

09-16 16:46:16.330: E/Web Console(27875): Uncaught ReferenceError:
plugins is not defined at file:///android_asset/www/index.html:74

This guy was facing the same problem but I referenced the cordova javascript file in index.html, but it still doesn’t work.

This is my package browser Looks like (you may find something missing):
I’m not sure if I should have plugins.xml or config.xml and plugins,
I’m just in case

Thanks in advance!

I changed LocalNotification.js, so you can copy the code. It works with cordova 2.0 (after Test!)

cordova.define("cordova/plugin/js/LocalNotification", function(require, exports, module) {

var exec = require("cordova/exec");
var LocalNotification = function () {};

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];
}

cordova.exec( null, null, "LocalNotification", "add", new Array(defaults));
};

LocalNotification.prototype.cancel = function(notificationId) {
cordova. exec(null, null,'LocalNotification','cancel', new Array({
id: notificationId
}));
};

LocalNotification.prototype .cancelAll = function() {
cordova.exec(null, null,'LocalNotification','cancelAll', new Array());
};


var LocalNotification = new LocalNotification();
module.exports = LocalNotification;

});

Now you can call the notification. There are:

datum = '2012-09-20 15:51:00'; 
tt1 = datum.split(/[- :]/);
dd = new Date(tt1[0], tt1[1]-1, tt1[2], tt1[3], tt1[4], tt1[5]);

window.plugins.LocalNotification.add ({ date: dd, message: "Some message", ticke r: "Some ticker", repeatDaily: false, id: 1234 });

I am currently trying to use the PhoneGap LocalNotification plug-in,
Android 4.1 and Cordova 2.0 .0 Used together with Sketcha (UI library).

Update #2 20/9/12: I used Bozzzi’s code and fixed some problems:

> Added }) to the end of localnotification.js (syntax error).
>Change cordova.define(“cordova/plugin/LocalNotification”, function (require, exports, module)) to:
cordova.define (“Cordova / plugin / LocalNotification”, function (require,exports,module),
So the module name will match this function (before the module is not found):

window.plugins.LocalNotification =
cordova.require(“cordova/plugin/LocalNotification”);

>Change this:

if (!window.plugins) {
window.plugins = {};
}
else if (!window.plugins.LocalNotification) {
window.plugins .LocalNotification = cordova.require(“cordova/plugin/LocalNotification”);
}

This:

if ( !window.plugins) {
window.plugins = {};
}

if (!window.plugins.LocalNotification) {
w indow.plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
}

Before this change, if window.plugins cannot be found, it will be created, but window.plugins.LocalNotification won’t.

After completing all these fixes, I received this error:

06001

< /blockquote>

For some reason, cordova.require(“cordova/plugins/LocalNotification”) does not set the window.plugins.LocalNotification value and it has been undefined.
This is my updated index.html (update #2):





AndroidSencha