San*_*eph 3 android localnotification phonegap-plugins cordova cordova-2.0.0
我正在Android上使用Phonegap [Cordova 2.2]开发"Reminders"应用程序.
用户输入提醒的具体日期,我应该按时通知他.
我使用Android的Notification Plugin,但它支持早期版本的手机差距.我按照本教程解决了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;
}
返回类型无法转换为布尔值,那么我该如何解决呢?
更新:
我将返回类型替换为boolean,现在就是这样:
    @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;
}
现在,它正在工作,但是当我点击通知时,应用程序无法打开,通知也没有消失......我该如何解决这个问题?
好的本地通知插件最终使用cordova 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
就是这样:)希望它有所帮助.
| 归档时间: | 
 | 
| 查看次数: | 5063 次 | 
| 最近记录: |