2012-04-18 68 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

相關問題