Katzer当地通知不起作用 - Cordova

时间:2015-03-24 08:40:18

标签: android cordova android-notifications localnotification

我正在谈论这个插件katzer/cordova-plugin-local-notifications

我在几个月前就用过了它。现在我发现它在很多方面发生了变化。所以我尝试创建一个简单的通知。

我安装了插件

cordova plugins add https://github.com/katzer/cordova-plugin-local-notifications

接下来我尝试了一些简单的

alert("enter");    

var now             = new Date().getTime(),
_5_sec_from_now = new Date(now + 5*1000);

cordova.plugins.notification.local.schedule({
    title: "Production Jour fixe",
    text: "Duration 1h",
    at: _5_sec_from_now,

});

alert("exit");  

什么都没发生,没有出现错误。两个警报都完美展示了。

然后我尝试了更简单的东西。

cordova.plugins.notification.local.schedule({ message:"Hello World" });

cordova.plugins.notification.local.get(0, function (notification) {
    alert(notification.text); //=> "Hello World"
    alert(notification.message); //=> undefined
});

再也没有。 Eclipse logcat 正在显示此

03-24 08:25:51.922: E/PluginManager(2422): Uncaught exception from plugin
03-24 08:25:51.922: E/PluginManager(2422): java.lang.NullPointerException
03-24 08:25:51.922: E/PluginManager(2422):  at de.appplant.cordova.plugin.localnotification.LocalNotification.execute(LocalNotification.java:133)
03-24 08:25:51.922: E/PluginManager(2422):  at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65)
03-24 08:25:51.922: E/PluginManager(2422):  at org.apache.cordova.PluginManager.execHelper(PluginManager.java:242)
03-24 08:25:51.922: E/PluginManager(2422):  at org.apache.cordova.PluginManager.exec(PluginManager.java:227)
03-24 08:25:51.922: E/PluginManager(2422):  at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
03-24 08:25:51.922: E/PluginManager(2422):  at android.webkit.JWebCoreJavaBridge.sharedTimerFired(Native Method)
03-24 08:25:51.922: E/PluginManager(2422):  at android.webkit.JWebCoreJavaBridge.sharedTimerFired(Native Method)
03-24 08:25:51.922: E/PluginManager(2422):  at android.webkit.JWebCoreJavaBridge.fireSharedTimer(JWebCoreJavaBridge.java:92)
03-24 08:25:51.922: E/PluginManager(2422):  at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:108)
03-24 08:25:51.922: E/PluginManager(2422):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 08:25:51.922: E/PluginManager(2422):  at android.os.Looper.loop(Looper.java:137)
03-24 08:25:51.922: E/PluginManager(2422):  at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:812)
03-24 08:25:51.922: E/PluginManager(2422):  at java.lang.Thread.run(Thread.java:856)
03-24 08:25:53.890: W/EGL_genymotion(2422): eglSurfaceAttrib not implemented
03-24 08:25:55.506: E/PluginManager(2422): Uncaught exception from plugin
03-24 08:25:55.506: E/PluginManager(2422): java.lang.NullPointerException
03-24 08:25:55.506: E/PluginManager(2422):  at de.appplant.cordova.plugin.localnotification.LocalNotification.execute(LocalNotification.java:133)
03-24 08:25:55.506: E/PluginManager(2422):  at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65)
03-24 08:25:55.506: E/PluginManager(2422):  at org.apache.cordova.PluginManager.execHelper(PluginManager.java:242)
03-24 08:25:55.506: E/PluginManager(2422):  at org.apache.cordova.PluginManager.exec(PluginManager.java:227)
03-24 08:25:55.506: E/PluginManager(2422):  at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewCore.nativeMouseClick(Native Method)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewCore.nativeMouseClick(Native Method)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewCore.access$6800(WebViewCore.java:57)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewCore$EventHub.dispatchWebKitEvent(WebViewCore.java:1788)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewInputDispatcher.dispatchWebKitEvent(WebViewInputDispatcher.java:689)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewInputDispatcher.dispatchWebKitEvents(WebViewInputDispatcher.java:639)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewInputDispatcher.access$800(WebViewInputDispatcher.java:78)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewInputDispatcher$WebKitHandler.handleMessage(WebViewInputDispatcher.java:1153)
03-24 08:25:55.506: E/PluginManager(2422):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 08:25:55.506: E/PluginManager(2422):  at android.os.Looper.loop(Looper.java:137)
03-24 08:25:55.506: E/PluginManager(2422):  at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:812)
03-24 08:25:55.506: E/PluginManager(2422):  at java.lang.Thread.run(Thread.java:856)
03-24 08:25:55.510: E/PluginManager(2422): Uncaught exception from plugin
03-24 08:25:55.510: E/PluginManager(2422): java.lang.NullPointerException
03-24 08:25:55.510: E/PluginManager(2422):  at de.appplant.cordova.plugin.localnotification.LocalNotification.execute(LocalNotification.java:133)
03-24 08:25:55.510: E/PluginManager(2422):  at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65)
03-24 08:25:55.510: E/PluginManager(2422):  at org.apache.cordova.PluginManager.execHelper(PluginManager.java:242)
03-24 08:25:55.510: E/PluginManager(2422):  at org.apache.cordova.PluginManager.exec(PluginManager.java:227)
03-24 08:25:55.510: E/PluginManager(2422):  at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewCore.nativeMouseClick(Native Method)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewCore.nativeMouseClick(Native Method)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewCore.access$6800(WebViewCore.java:57)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewCore$EventHub.dispatchWebKitEvent(WebViewCore.java:1788)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewInputDispatcher.dispatchWebKitEvent(WebViewInputDispatcher.java:689)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewInputDispatcher.dispatchWebKitEvents(WebViewInputDispatcher.java:639)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewInputDispatcher.access$800(WebViewInputDispatcher.java:78)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewInputDispatcher$WebKitHandler.handleMessage(WebViewInputDispatcher.java:1153)
03-24 08:25:55.510: E/PluginManager(2422):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 08:25:55.510: E/PluginManager(2422):  at android.os.Looper.loop(Looper.java:137)
03-24 08:25:55.510: E/PluginManager(2422):  at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:812)
03-24 08:25:55.510: E/PluginManager(2422):  at java.lang.Thread.run(Thread.java:856)

我在Genymotion模拟器4.2.2设备图像& Xperia - android 4.4.4。我等待设备准备事件发生了。 js中没有其他错误。谁能告诉我我失踪了什么?有什么不对吗?

2 个答案:

答案 0 :(得分:1)

问题的原因没有找到,但这是解决方案。

这是一个较旧的项目,目标sdk为16,所以我将其更新为19。

重新安装所有插件。它现在正在工作。我猜它是某种依赖/版本错误。使用新的插件版本,它可以按预期工作。

答案 1 :(得分:0)

为了我的项目(因为它是一个遗留项目,尽管它指向sdk 19)我不得不使用版本0.7.8并且nullPointerException消失了,一切都开始完美。

<强>程序

  1. 首先删除当前插件,这是最新版本。

    $ phonegap plugin rm de.appplant.cordova.plugin.local-notification
    
  2. 然后安装0.7.8版本

    $ phonegap plugin add de.appplant.cordova.plugin.local-notification@0.7.8
    
  3. 然后是docs for that version

    <强>疑难解答

    如果您遇到phonegap plugin rm问题,可以尝试重新安装最新版本并卸载以便正确安装0.7.8。

    为了成功安装0.7.8版本,我必须从de.applant.cordova.plugin.localnotification删除一些/src个包,并从{{删除 js 文件夹de.appplant.cordova.plugin.local-notification 1}}。