2012-04-18 75 views
3

我想升级使用LocalNotification插件为Android科尔多瓦-1.6.0试图让Android的LocalNotification插件PhoneGap的科尔多瓦的-1.6.0

一个PhoneGap的-1.4.1项目工作我在这里找到这个链接:https://github.com/davejohnson/phonegap-plugin-facebook-connect/pull/109 它说的对于Android:使用CordovaInterface对象的this.ctx.getContext()方法来获得Conext对象。

我编辑LocalNotification.java并得到我的项目通过更改以下行没有错误编译:

来源:

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(); 

为:

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

如果我删除了,如果条件的typeof插件==“未定义”然后我得到一个错误!我的应用程序日志是:未捕获ReferenceError:插件未定义

我想其他东西在科尔多瓦更改。如果有一个指导将android插件升级到cordova的话,那将是有用的。

回答

3

升级到今天科尔多瓦-1.6.1,它现在的作品;)

足够的勇气承认,它可能是一个“椅子/键盘”接口问题。 认为当我升级到1.6.0我忘了改变它在我的index.html标头

+0

+1拥有:) – SteveCav 2012-05-02 05:24:16

+0

'localNotification.cancelAll'是否适合你? https://github.com/phonegap/phonegap-plugins/issues/549 – 2012-05-08 11:37:01

+0

刚刚在我使用cordova-1.6.1的项目中尝试过,您的权利cancelAll不起作用。我之前没有注意到,因为我取消了使用ID。 – 2012-05-16 20:45:33

2

好像getContext()已被折旧。这个问题有没有更清晰的解决方案?

+0

我认为getActivity()是替代方法。 – cdmdotnet 2013-03-23 09:29:57

+0

是的,它是... cordova.getActivity() – MontDeska 2015-07-09 18:46:59

相关问题