Phonegap [Cordova 2.2] を使用して、Android の「リマインダー」アプリケーションに取り組んでいます。
ユーザーがリマインダーの特定の日付を入力すると、私は時間通りにユーザーに通知することになっています。
私は Android の Notification Plugin を使用していますが、以前のバージョンの phone gap をサポートしています。このチュートリアルに従って、cordova 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;
}
現在は動作していますが、通知をクリックしてもアプリケーションが開かず、通知が消えません...どうすれば修正できますか?