Trying to get the Android LocalNotification plugins for phonegap to work in cordova-1.6.0

≡放荡痞女 提交于 2019-12-06 08:11:10

问题


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.


回答1:


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




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!