I'm trying to upgrade a phonegap-1.4.1 project that uses the LocalNotification plugin for Android to cordova-1.6.0
I found this link here: https://github.com/davejohnson/phonegap-plugin-facebook-connect/pull/109 Where it says, For Android: use this.ctx.getContext() method of CordovaInterface object to get Conext object.
I edited LocalNotification.java and got my project to compile without errors by changing the following lines:
From:
alarm = new AlarmHelper(this.ctx);
...
final SharedPreferences alarmSettings = this.ctx.getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE);
...
final Editor alarmSettingsEditor = this.ctx.getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit();
...
final Editor alarmSettingsEditor = this.ctx.getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit();
...
final Editor alarmSettingsEditor = this.ctx.getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit();
To:
alarm = new AlarmHelper(this.ctx.getContext());
...
final SharedPreferences alarmSettings = this.ctx.getContext().getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE);
...
final Editor alarmSettingsEditor = this.ctx.getContext().getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit();
...
final Editor alarmSettingsEditor = this.ctx.getContext().getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit();
...
final Editor alarmSettingsEditor = this.ctx.getContext().getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit();
However I must admit that I don't really know what I'm doing and the notifications don't work and I don't get any errors in the applications log :(
Also just noticed that as per the example in my onDeviceReady() function I have the following:
console.log("Device ready");
if (typeof plugins !== "undefined") {
plugins.localNotification.add({
date : new Date(),
message : "Phonegap - Local Notification\r\nSubtitle comes after linebreak",
ticker : "This is a sample ticker text",
repeatDaily : false,
id : 4
});
}
If I remove the the if condition typeof plugins !== "undefined" then I get an error in my app log which is: Uncaught ReferenceError: plugins is not defined
I guess something else as changed in cordova. If there is a guide somewhere for upgrading android plugins to cordova if would be useful.
Upgraded to Cordova-1.6.1 today and it now works ;)
Brave enough to admit that it might have been a "chair/keyboard" interface issue. Think when I upgraded to 1.6.0 I forgot to change it in the header of my index.html
Seems like getContext() has been depreciated. Is there a cleaner solution to this issue?
来源:https://stackoverflow.com/questions/10218745/trying-to-get-the-android-localnotification-plugins-for-phonegap-to-work-in-cord