Worklight 应用程序在收到推送通知时崩溃

Posted

技术标签:

【中文标题】Worklight 应用程序在收到推送通知时崩溃【英文标题】:Worklight app crashes when receiving push notification 【发布时间】:2014-10-09 13:13:18 【问题描述】:

您好,我已经为 android 开发了一个 Worklight 应用程序,它使用 Bluemix IBM Push,当我收到通知时,如果应用程序关闭,它可以正常工作并打开应用程序,但是当应用程序打开时,应用程序崩溃并显示以下内容错误。

10-09 18:13:00.676: E/AndroidRuntime(4665): FATAL EXCEPTION: main
10-09 18:13:00.676: E/AndroidRuntime(4665): java.lang.ClassCastException: com.ibm.mobile.services.push.internal.InternalPushMessage cannot be cast to com.worklight.androidgap.push.GCMIntentService$Message
10-09 18:13:00.676: E/AndroidRuntime(4665):     at com.worklight.androidgap.plugin.Push.onNewIntent(Push.java:193)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at org.apache.cordova.PluginManager.onNewIntent(PluginManager.java:371)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at org.apache.cordova.CordovaWebView.onNewIntent(CordovaWebView.java:874)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at org.apache.cordova.CordovaActivity.onNewIntent(CordovaActivity.java:702)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1225)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2472)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.app.ActivityThread.performNewIntents(ActivityThread.java:2485)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2494)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.app.ActivityThread.access$1400(ActivityThread.java:165)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1444)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.os.Handler.dispatchMessage(Handler.java:107)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.os.Looper.loop(Looper.java:194)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at android.app.ActivityThread.main(ActivityThread.java:5391)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at java.lang.reflect.Method.invokeNative(Native Method)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at java.lang.reflect.Method.invoke(Method.java:525)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
10-09 18:13:00.676: E/AndroidRuntime(4665):     at dalvik.system.NativeStart.main(Native Method)
10-09 18:13:00.677: D/WLClient(4665): WLClient$ActivityListener.onActivityPaused in WLClient.java:1155 :: on activity paused com.Techathon.Techathon . activity count = 0
10-09 18:13:00.683: D/NONE(4665): Flush called
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665): Logger$UncaughtExceptionHandler.uncaughtException in Logger.java:402 :: Uncaught Exception
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665): java.lang.ClassCastException: com.ibm.mobile.services.push.internal.InternalPushMessage cannot be cast to com.worklight.androidgap.push.GCMIntentService$Message
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at com.worklight.androidgap.plugin.Push.onNewIntent(Push.java:193)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at org.apache.cordova.PluginManager.onNewIntent(PluginManager.java:371)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at org.apache.cordova.CordovaWebView.onNewIntent(CordovaWebView.java:874)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at org.apache.cordova.CordovaActivity.onNewIntent(CordovaActivity.java:702)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1225)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2472)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.app.ActivityThread.performNewIntents(ActivityThread.java:2485)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2494)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.app.ActivityThread.access$1400(ActivityThread.java:165)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1444)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.os.Handler.dispatchMessage(Handler.java:107)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.os.Looper.loop(Looper.java:194)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at android.app.ActivityThread.main(ActivityThread.java:5391)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at java.lang.reflect.Method.invokeNative(Native Method)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at java.lang.reflect.Method.invoke(Method.java:525)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
10-09 18:13:00.718: E/com.worklight.common.Logger$UncaughtExceptionHandler(4665):   at dalvik.system.NativeStart.main(Native Method)
10-09 18:13:02.586: I/Process(4665): Sending signal. PID: 4665 SIG: 9

我已经根据此处提供的链接设置了我的环境http://mbaas-gettingstarted.ng.bluemix.net/hybrid

【问题讨论】:

【参考方案1】:

您是否尝试过编辑您的 AndroidManifest.xml 以删除对 GCMIntentService 的引用?

您也许可以按照此处的说明注释掉这些部分: https://developer.ibm.com/answers/questions/19343/double-push-notifications/?smartspace=bluemix

这样,您将只使用 Bluemix Push SDK 来响应推送通知。希望完全避免这个错误。

编辑:玩了一段时间后,我发现 Push 插件应该归咎于 SDK 冲突。在我注释掉 config.xml 中的 Worklight Push 插件后,错误消失了。

评论这些行并重试:

<feature name="Push">
     <param name="android-package" value="com.worklight.androidgap.plugin.Push" />
</feature>

【讨论】:

以上是关于Worklight 应用程序在收到推送通知时崩溃的主要内容,如果未能解决你的问题,请参考以下文章

IBM Worklight 5.0.6.1 - 关闭电话/应用程序时未收到推送通知

Worklight 推送导致 ConcurrentModificationException

关于 Worklight 中的推送通知?

Worklight 6.2:成功发送标签推送通知,但在 android 设备上未收到

iPhone 应用程序在收到推送通知时崩溃

发送推送通知时出现 Worklight 错误