3

我正在使用Phonegap [Cordova 2.2]在Android上的「提醒」應用程序。Cordova本地通知Android插件2.2升級

用戶輸入提醒的具體日期,我應該按時通知他。

我使用Android的通知插件,但它支持早期版本的手機差距。我跟着這個教程解決科爾多瓦2.2和以前的,現在很多的問題已得到修復之間的衝突,但我仍然無法修復一些:

public PluginResult execute(String action, JSONArray optionsArr, String callBackId) { 
    alarm = new AlarmHelper(cordova.getActivity()); 
    Log.d(PLUGIN_NAME, "Plugin execute called with action: " + action); 

    PluginResult result = null; 

    final AlarmOptions alarmOptions = new AlarmOptions(); 
    alarmOptions.parseOptions(optionsArr); 

此功能與此行的一個問題:

 public PluginResult execute(String action, JSONArray optionsArr, String callBackId) 

,當我用下面這行替換:

public boolean execute(String action, JSONArray optionsArr, CallbackContext callbackContext) { 

誤差是固定的,但另一錯誤示出了在這樣的功能:

persistAlarm(alarmId, optionsArr); 
     return this.add(daily, title, subTitle, ticker, alarmId, alarmOptions.getCal()); 
    } else if (action.equalsIgnoreCase("cancel")) { 
     unpersistAlarm(alarmId); 
     return this.cancelNotification(alarmId); 
    } else if (action.equalsIgnoreCase("cancelall")) { 
     unpersistAlarmAll(); 
     return this.cancelAllNotifications(); 
    } 

    return result; 
} 

返回類型無法轉換爲布爾值,那麼我該如何解決它?

更新:

我更換了返回類型爲布爾的,這就是它的現在:

@Override 
public boolean execute(String action, JSONArray optionsArr, CallbackContext callBackId) 
{ 
    Log.d(PLUGIN_NAME, "optionsArr: " + optionsArr.toString()); 
    alarm = new AlarmHelper(cordova.getActivity()); 
    Log.d(PLUGIN_NAME, "Plugin execute called with action: " + action); 

//PluginResult result = null; 
boolean result = true; 

final AlarmOptions alarmOptions = new AlarmOptions(); 
alarmOptions.parseOptions(optionsArr); 

/* 
* Determine which action of the plugin needs to be invoked 
*/ 
String alarmId = alarmOptions.getNotificationId(); 
if (action.equalsIgnoreCase("add")) { 
    final boolean daily = alarmOptions.isRepeatDaily(); 
    final String title = alarmOptions.getAlarmTitle(); 
    final String subTitle = alarmOptions.getAlarmSubTitle(); 
    final String ticker = alarmOptions.getAlarmTicker(); 
    persistAlarm(alarmId, optionsArr); 
    this.add(daily, title, subTitle, ticker, alarmId, alarmOptions.getCal()); 
    callBackId.success(); 
    return true; 
} 
else if (action.equalsIgnoreCase("cancel")) { 
    unpersistAlarm(alarmId); 
    this.cancelNotification(alarmId); 
    callBackId.success(); 
    return true; 
} 
else if (action.equalsIgnoreCase("cancelall")) { 
    unpersistAlarmAll(); 
    this.cancelAllNotifications(); 
    callBackId.success(); 
    return true;   
} 
return result; 
} 

現在,它的工作,但是當我點擊該通知,該應用程序沒有按不開放,通知沒有消失......我該如何解決這個問題?

回答

6

OK了本地通知插件最後用科爾多瓦2個工作。2 :) 現在,這裏是修改需要:

1)更換

import com.phonegap.api.Plugin; 
import com.phonegap.api.PluginResult; 

import org.apache.cordova.api.CordovaPlugin; 
import org.apache.cordova.api.PluginResult; 

2)更換

public PluginResult execute(String action, JSONArray optionsArr, String callBackId) 

public pluginresult execute(String action, JSONArray args, CallbackContext callbackContext) 

3)添加

callbackContext.success(); 
return true; 

return false; 

作爲函數的返回類型。

4)更換

this.ctx 

cordova.getActivity() 

5)添加

import yourapplication.name.R; 

AlarmReciever.Java

這就是它 :) 希望能幫助到你。

1

您必須使用您的callbackContext才能將其他數據返回給您的成功/錯誤處理程序。 返回值必須是布爾值。

2

與「公佈爾執行」功能,替換和在成功添加

callbackContext.success(); 
return true; 

,失敗:

return false; 
+0

我更新了你所說的解決方案,但我不知道我什麼時候應該使用故障情況? –

2

整個文件包括薩娜約瑟夫的意見都可以在這裏找到:我創造了這個

https://github.com/Philzen/phonegap-plugins/tree/master/Android/LocalNotification

後,我還發現https://github.com/olore/LocalNotifications,這也允許使用科爾多瓦pluginstall。

通知被創建並附帶了罰款,使用任何這些解決方案,但是 - 當我點擊它:(這」既不消失也不打開應用程序沒有任何反應

任何線索什麼我可能會丟失?

+1

檢查Joe的答案在這個問題:http://stackoverflow.com/questions/13798021/clear-androids-local-notifications-cordova-plugin –

+0

它沒有爲我工作,但它爲很多人工作。 –

+1

明確地創建啓動我的應用程序的意圖適用於我,如上面提供的Joe的回答鏈接中所述。 想知道這可以隱式地工作 - 當然必須有一種方法來獲取調用'LocalNotification'的應用程序包名 - 不應該需要編輯Java源文件來包含插件。 – Philzen

1

僅供參考 也

變化

LocalNotification extends Plugin 

LocalNotification extends CordovaPlugin 

它爲我工作