Cordova Local Notification Android Plugin 2.2 upgrade

自古美人都是妖i 提交于 2019-11-30 16:09:01
Sana Joseph

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

1) Replace

import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;

with

import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;

2) Replace

public PluginResult execute(String action, JSONArray optionsArr, String callBackId)

with

public pluginresult execute(String action, JSONArray args, CallbackContext callbackContext)

3) Add

callbackContext.success();
return true;

or

return false; 

as the return type of the function.

4) Replace

this.ctx

with

cordova.getActivity()

5)Add

import yourapplication.name.R;

To AlarmReciever.Java

That's it :) Hope it helps.

replace it with the "public boolean execute" function and On success add

callbackContext.success();
return true;

and on failure:

return false;

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.

fyi also

change

LocalNotification extends Plugin

for

LocalNotification extends CordovaPlugin

it works for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!