I'm working on a "Reminders" application on Android using Phonegap[Cordova 2.2].
The user enters a specific date for his reminder and I'm supposed to notify him on time.
I use Android's Notification Plugin but it supports earlier versions of phone gap. I followed this tutorial to resolve conflicts between cordova 2.2 and previous ones, now a lot of issues have been fixed, but I still can't fix some:
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);
This function has a problem with this line:
public PluginResult execute(String action, JSONArray optionsArr, String callBackId)
and when I replace it with this line:
public boolean execute(String action, JSONArray optionsArr, CallbackContext callbackContext) {
The error is fixed, but another error shows at this function:
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;
}
That the return type cannot be converted to boolean, So how can I fix it ?
Update:
I replaced the return type to be boolean and that's how it is now:
@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;
}
Now , it's working, but when I click on the notification, the application doesn't open and the notification isn't gone ... how can I fix this ?
The whole file including Sana Joseph's comments can be found here:
https://github.com/Philzen/phonegap-plugins/tree/master/Android/LocalNotification
After i had created this, i also found https://github.com/olore/LocalNotifications, which also allows to use cordova pluginstall.
The notification is created and comes up fine using any of these solutions, however - nothing happens when i click on it :( It' neither disappears nor opens the application.
Any clues what i might be missing?
you must use your
callbackContext
in order to return additional data to your success/error handlers. the return value must be a boolean.Ok the local notifications plugin is finally working with cordova 2.2 :) Now here are the modifications needed:
1) Replace
with
2) Replace
with
3) Add
or
as the return type of the function.
4) Replace
with
5)Add
To AlarmReciever.Java
That's it :) Hope it helps.
fyi also
change
for
it works for me
replace it with the "public boolean execute" function and On success add
and on failure: