我正在使用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;
}
現在,它的工作,但是當我點擊該通知,該應用程序沒有按不開放,通知沒有消失......我該如何解決這個問題?
我更新了你所說的解決方案,但我不知道我什麼時候應該使用故障情況? –