科尔多瓦本地通知Android插件2.2升级 [英] Cordova Local Notification Android Plugin 2.2 upgrade

查看:175
本文介绍了科尔多瓦本地通知Android插件2.2升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的PhoneGap [科尔多瓦2.2。一个提醒的Andr​​oid应用程序

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.

我用Android的通知插件,但它支持早期版本的手机的差距。我跟着这个教程来解决科尔多瓦2.2和previous的,现在很多问题都得到解决之间的冲突,但我还是无法修复一些:

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) 

和我有这行替换它:

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;
}

这是返回类型不能转换为Boolean,那么,如何解决这个问题?

That the return type cannot be converted to boolean, So how can I fix it ?

更新:

我更换了返回类型是布尔值,这就是它现在怎么是:

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 ?

推荐答案

确定的本地通知插件终于在与科尔多瓦2.2 :) 现在,这里是修改必要的:

Ok the local notifications plugin is finally working with cordova 2.2 :) Now here are the modifications needed:

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; 

作为函数的返回类型。

as the return type of the function.

4)更换

this.ctx

cordova.getActivity()

5)添加

import yourapplication.name.R;

AlarmReciever.Java

这就是它:)希望它帮助。

That's it :) Hope it helps.

这篇关于科尔多瓦本地通知Android插件2.2升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆