我正在尝试将使用适用于 Android 的 LocalNotification 插件的 Phonegap-1.4.1 项目升级到 cordova-1.6.0
我在这里找到了这个链接:https://github.com/davejohnson/phonegap-plugin-facebook-connect/pull/109 https://github.com/davejohnson/phonegap-plugin-facebook-connect/pull/109其中说,对于 Android:使用 CordovaInterface 对象的 this.ctx.getContext() 方法来获取 Conext 对象。
我编辑了 LocalNotification.java 并通过更改以下行使我的项目编译没有错误:
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();
但我必须承认,我真的不知道自己在做什么,而且通知不起作用,而且我在应用程序日志中没有收到任何错误:(
另外还注意到,根据我的 onDeviceReady() 函数中的示例,我有以下内容:
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 条件 typeof plugins !== "undefined" 那么我会在我的应用程序日志中收到一个错误: Uncaught ReferenceError: plugins is not Defined
我猜科尔多瓦还有其他事情发生了变化。如果有一个将 android 插件升级到 cordova 的指南会有用。