IBM Worklight 5.0.6.1 - Android 通知未到达设备或模拟器

Posted

技术标签:

【中文标题】IBM Worklight 5.0.6.1 - Android 通知未到达设备或模拟器【英文标题】:IBM Worklight 5.0.6.1 - Android notification does not reach either device or emulator 【发布时间】:2013-12-12 18:13:53 【问题描述】:

我遵循了Push Notifications training module 中给出的所有步骤,以及这个 Stack Overflow 问题:IBM Worklight - Push Notifications feature does not work in android emulator

当我使用 PushBackendEmulator 或通过从 URL 调用 PushAdapter 过程发送消息时,它显示 message sent successfully,但在任何设备或模拟器中都没有收到通知,并且 LogCat 中没有错误。

我正在使用运行 Android OS 4.3 的设备和运行 Android OS 4.0.3 的 AVD。 我正在尝试使用推送通知入门培训模块示例。

application-descriptor.xml中,我设置了:

<pushSender key="AIzaSyDXNiXutgh9XhX8eB8AFa2-00jbyVWM2zI" senderId="470484369549"/> 

senderID 是项目编号:

key 取自 Google APIs Console:通过 Create new Server Key 选项

当我在设备上运行应用程序并执行推送适配器以发送推送消息时,Eclipse Studio 控制台会给出以下异常:

[2013-12-27 06:18:12]             Invoking procedure: 'submitNotification' of adapter 'PushAdapter'
[2013-12-27 06:18:12]             Server host: localhost
[2013-12-27 06:18:12]             Server port: 8080
[2013-12-27 06:18:12]             Parameters: ["aahad","this is example"]
[2013-12-27 06:18:12]             Procedure invocation finished
[2013-12-27 06:18:13] FWLSE0094E: Error while attempting to invoke GCM service (for sender key starting with 'AIzaSyDX'), sending will not resume until server is restarted or application re-deployed
[2013-12-27 06:18:13] FWLSE0093E: Failed to invoke Google GCM push service.
                                  com.worklight.integration.notification.gcm.GCMSender.sendNoRetry(GCMSender.java:225)
                                  com.worklight.integration.notification.gcm.GCMSender.sendAndVerify(GCMSender.java:127)
                                  com.worklight.integration.notification.gcm.GCMMediator.sendOrWait(GCMMediator.java:135)
                                  com.worklight.integration.notification.gcm.GCMMediator.sendNotification(GCMMediator.java:124)
                                  com.worklight.integration.notification.Mediator$4.run(Mediator.java:174)
                                  java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
                                  java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
                                  java.util.concurrent.FutureTask.run(Unknown Source)
                                  java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
                                  java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                                  java.lang.Thread.run(Unknown Source)
[2013-12-27 06:18:13] FWLSE0094E: Error while attempting to invoke GCM service (for sender key starting with 'AIzaSyDX'), sending will not resume until server is restarted or application re-deployed
[2013-12-27 06:18:13] FWLSE0094E: Error while attempting to invoke GCM service (for sender key starting with 'AIzaSyDX'), sending will not resume until server is restarted or application re-deployed
[2013-12-27 06:18:13] FWLSE0094E: Error while attempting to invoke GCM service (for sender key starting with 'AIzaSyDX'), sending will not resume until server is restarted or application re-deployed
[2013-12-27 06:18:13] FWLSE0094E: Error while attempting to invoke GCM service (for sender key starting with 'AIzaSyDX'), sending will not resume until server is restarted or application re-deployed
[2013-12-27 06:18:13] FWLSE0093E: Failed to invoke Google GCM push service.
                                  com.worklight.integration.notification.gcm.GCMSender.sendNoRetry(GCMSender.java:225)
                                  com.worklight.integration.notification.gcm.GCMSender.sendAndVerify(GCMSender.java:127)
                                  com.worklight.integration.notification.gcm.GCMMediator.sendOrWait(GCMMediator.java:135)
                                  com.worklight.integration.notification.gcm.GCMMediator.sendNotification(GCMMediator.java:124)
                                  com.worklight.integration.notification.Mediator$4.run(Mediator.java:174)
                                  java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
                                  java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
                                  java.util.concurrent.FutureTask.run(Unknown Source)
                                  java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
                                  java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                                  java.lang.Thread.run(Unknown Source)

LogCat 显示:

12-27 17:26:47.750: D/Cordova(5639): onPageFinished(file:///data/data/com.PushApplication/files/www/default/PushApplication.html)
12-27 17:26:47.750: D/DroidGap(5639): onMessage(onNativeReady,null)
12-27 17:26:47.750: D/DroidGap(5639): onMessage(onPageFinished,file:///data/data/com.PushApplication/files/www/default/PushApplication.html)
12-27 17:26:47.850: D/CordovaNetworkManager(5639): Connection Type: wifi
12-27 17:26:47.850: D/CordovaNetworkManager(5639): Connection Type: wifi
12-27 17:26:47.850: D/DroidGap(5639): onMessage(networkconnection,wifi)
12-27 17:26:47.860: D/DroidGap(5639): onMessage(spinner,stop)
12-27 17:26:47.860: D/PushApplication(5639): ondeviceready event dispatched
12-27 17:26:47.870: D/PushApplication(5639): wlclient init started
12-27 17:26:47.870: D/PushApplication(5639): Read cookies: null
12-27 17:26:47.880: D/PushApplication(5639): CookieMgr read cookies: 
12-27 17:26:48.870: D/DroidGap(5639): onMessage(spinner,stop)
12-27 17:26:49.220: D/PushApplication(5639): Request [http://192.168.48.69:8080/apps/services/api/PushApplication/android/init]
12-27 17:26:49.490: D/PushApplication(5639): Request [http://192.168.48.69:8080/apps/services/api/PushApplication/android/init]
12-27 17:26:49.640: D/PushApplication(5639): Clearing notification subscriptions.
12-27 17:26:49.640: D/PushApplication(5639): Send new server notification token id.
12-27 17:26:49.640: W/WLDroidGap(5639): unregisterReceivers:Receiver not registered: com.worklight.androidgap.plugin.Push$1@420ee688
12-27 17:26:49.640: W/WLDroidGap(5639): unregisterReceivers:Receiver not registered: com.worklight.androidgap.plugin.Push$3@420eebb8
12-27 17:26:49.680: D/dalvikvm(5639): GC_FOR_ALLOC freed 334K, 5% free 7765K/8164K, paused 15ms, total 16ms
12-27 17:26:49.680: D/WLDroidGap(5639): Registering at the GCM server.
12-27 17:26:49.680: V/GCMRegistrar(5639): Registering receiver
12-27 17:26:49.680: D/GCMRegistrar(5639): resetting backoff for com.PushApplication
12-27 17:26:49.690: D/PushApplication(5639): response [http://192.168.48.69:8080/apps/services/api/PushApplication/android/init] success: /*-secure-
12-27 17:26:49.690: D/PushApplication(5639): "userPrefs":,"WL-Authentication-Success":"wl_remoteDisableRealm":"userId":"null","attributes":,"isUserAuthenticated":1,"displayName":"null","wl_antiXSRFRealm":"userId":"ce6ll85omecut37aatqrfojfj5","attributes":,"isUserAuthenticated":1,"displayName":"ce6ll85omecut37aatqrfojfj5","wl_deviceNoProvisioningRealm":"userId":"b65b4d32-93aa-4d2d-89ab-bff0a8c7c9af","attributes":"mobileClientData":"com.worklight.core.auth.impl.MobileClientData@2c70f885","isUserAuthenticated":1,"displayName":"b65b4d32-93aa-4d2d-89ab-bff0a8c7c9af","wl_anonymousUserRealm":"userId":"5125bfe6-d34c-4dce-b5cd-e6c76d902536","attributes":,"isUserAuthenticated":1,"displayName":"5125bfe6-d34c-4dce-b5cd-e6c76d902536","notificationSubscriptionState":,"gadgetProps":"directUpdate":"updateUnpackedSize":1019860,"availableSkins":["default"],"checksum":695958230,"updateSize":290361,"ENVIRONMENT":"android","userInfo":"wl_authenticityRealm":"userId":null,"attributes":,"isUserAuthenticated":0,"displayName":null,"wl_remoteDisableRealm":"userId":"null","attributes":,"isUserAuthenticated":1,"displayName":"null","PushAppRealm":"userId":null,"attributes":,"isUserAuthenticated":0,"displayName":null,"wl_antiXSRFRealm":"userId":"ce6ll85omecut37aatqrfojfj5","attributes":,"isUserAuthenticated":1,"displayName":"ce6ll85omecut37aatqrfojfj5","wl_deviceAutoProvisioningRealm":"userId":null,"attributes":,"isUserAuthenticated":0,"displayName":null,"wl_deviceNoProvisioningRealm":"userId":"b65b4d32-93aa-4d2d-89ab-bff0a8c7c9af","attributes":"mobileClientData":"com.worklight.core.auth.impl.MobileClientData@2c70f885","isUserAuthenticated":1,"displayName":"b65b4d32-93aa-4d2d-89ab-bff0a8c7c9af","myserver":"userId":"5125bfe6-d34c-4dce-b5cd-e6c76d902536","attributes":,"isUserAuthenticated":1,"displayName":"5125bfe6-d34c-4dce-b5cd-e6c76d902536","wl_anonymousUserRealm":"userId":"5125bfe6-d34c-4dce-b5cd-e6c76d902536","attributes":,"isUserAuthenticated":1,"displayName":"5125bfe6-d34c-4dce-b5cd-e6c76d902536"*/
12-27 17:26:49.690: D/PushApplication(5639): wlclient connect success
12-27 17:26:49.690: D/PushApplication(5639): before: app init onSuccess
12-27 17:26:49.700: D/PushApplication(5639): after: app init onSuccess
12-27 17:26:49.700: D/PushApplication(5639): wlclient init success
12-27 17:26:49.700: V/GCMRegistrar(5639): Registering app com.PushApplication of senders 470484369549
12-27 17:26:50.190: V/GCMBroadcastReceiver(5639): onReceive: com.google.android.c2dm.intent.REGISTRATION
12-27 17:26:50.190: V/GCMBroadcastReceiver(5639): GCM IntentService class: com.PushApplication.GCMIntentService
12-27 17:26:50.200: V/GCMBaseIntentService(5639): Acquiring wakelock
12-27 17:26:50.200: V/GCMBaseIntentService(5639): Intent service name: GCMIntentService-470484369549-1
12-27 17:26:50.210: D/GCMBaseIntentService(5639): handleRegistration: registrationId = APA91bEGLOHqoQHlmmb-wLCEzKFxrW2UHKaeMWnheA8nebNXNojI6O7o3B4BOnAc_tFXe8H3rsg6g4JH3mQl2vh5p8DxXbNhHgiSts-q2HFYFAT1l07Il-2QiRS0ypHLD4kGFQss0ueZWymkzOxypsFBQKPvezKq3Q, error = null, unregistered = null
12-27 17:26:50.210: D/GCMRegistrar(5639): resetting backoff for com.PushApplication
12-27 17:26:50.210: V/GCMRegistrar(5639): Saving regId on app version 1
12-27 17:26:50.210: D/WLDroidGap(5639): Registered at the GCM server with registration id APA91bEGLOHqoQHlmmb-wLCEzKFxrW2UHKaeMWnheA8nebNXNojI6O7o3B4BOnAc_tFXe8H3rsg6g4JH3mQl2vh5p8DxXbNhHgiSts-q2HFYFAT1l07Il-2QiRS0ypHLD4kGFQss0ueZWymkzOxypsFBQKPvezKq3Q
12-27 17:26:50.220: D/WLDroidGap(5639): Successfully registered to GCM notification service with token id APA91bEGLOHqoQHlmmb-wLCEzKFxrW2UHKaeMWnheA8nebNXNojI6O7o3B4BOnAc_tFXe8H3rsg6g4JH3mQl2vh5p8DxXbNhHgiSts-q2HFYFAT1l07Il-2QiRS0ypHLD4kGFQss0ueZWymkzOxypsFBQKPvezKq3Q
12-27 17:26:50.220: V/GCMBaseIntentService(5639): Releasing wakelock
12-27 17:26:50.220: D/PushApplication(5639): Push notification device token has changed, updating server notification token id.
12-27 17:26:50.230: D/PushApplication(5639): Request [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications]
12-27 17:26:50.440: D/PushApplication(5639): response [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications] success: /*-secure-
12-27 17:26:50.440: D/PushApplication(5639): "errors":[],"isSuccessful":true,"warnings":[],"info":[]*/
12-27 17:27:04.920: D/PushApplication(5639): Request [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications]
12-27 17:27:06.900: D/SoftKeyboardDetect(5639): Ignore this event
12-27 17:27:07.000: D/SoftKeyboardDetect(5639): Ignore this event
12-27 17:27:12.060: D/SoftKeyboardDetect(5639): Ignore this event
12-27 17:27:12.070: W/IInputConnectionWrapper(5639): getTextBeforeCursor on inactive InputConnection
12-27 17:27:12.080: W/IInputConnectionWrapper(5639): getTextBeforeCursor on inactive InputConnection
12-27 17:27:12.170: D/SoftKeyboardDetect(5639): Ignore this event
12-27 17:27:16.120: D/SoftKeyboardDetect(5639): Ignore this event
12-27 17:27:17.910: D/PushApplication(5639): Request [login]
12-27 17:27:20.750: D/PushApplication(5639): Request [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications]
12-27 17:27:20.780: D/PushApplication(5639): Clearing notification subscriptions.
12-27 17:27:20.780: D/PushApplication(5639): Updating notification subscriptions.
12-27 17:27:20.790: D/WLDroidGap(5639): Registering at the GCM server.
12-27 17:27:20.790: D/PushApplication(5639): response [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications] success: /*-secure-
12-27 17:27:20.790: D/PushApplication(5639): "isSuccessful":true,"WL-Authentication-Success":"PushAppRealm":"userId":"aahad","attributes":,"isUserAuthenticated":1,"displayName":"aahad","notificationSubscriptionState":"eventSources":["eventSource":"PushEventSource","alias":"myPush","adapter":"PushAdapter"],"token":"APA91bEGLOHqoQHlmmb-wLCEzKFxrW2UHKaeMWnheA8nebNXNojI6O7o3B4BOnAc_tFXe8H3rsg6g4JH3mQl2vh5p8DxXbNhHgiSts-q2HFYFAT1l07Il-2QiRS0ypHLD4kGFQss0ueZWymkzOxypsFBQKPvezKq3Q"*/
12-27 17:27:20.790: D/GCMRegistrar(5639): resetting backoff for com.PushApplication
12-27 17:27:20.790: V/GCMRegistrar(5639): Registering app com.PushApplication of senders 470484369549
12-27 17:27:21.500: V/GCMBroadcastReceiver(5639): onReceive: com.google.android.c2dm.intent.REGISTRATION
12-27 17:27:21.500: V/GCMBroadcastReceiver(5639): GCM IntentService class: com.PushApplication.GCMIntentService
12-27 17:27:21.500: V/GCMBaseIntentService(5639): Acquiring wakelock
12-27 17:27:21.510: V/GCMBaseIntentService(5639): Intent service name: GCMIntentService-470484369549-2
12-27 17:27:21.510: D/GCMBaseIntentService(5639): handleRegistration: registrationId = APA91bEGLOHqoQHlmmb-wLCEzKFxrW2UHKaeMWnheA8nebNXNojI6O7o3B4BOnAc_tFXe8H3rsg6g4JH3mQl2vh5p8DxXbNhHgiSts-q2HFYFAT1l07Il-2QiRS0ypHLD4kGFQss0ueZWymkzOxypsFBQKPvezKq3Q, error = null, unregistered = null
12-27 17:27:21.510: D/GCMRegistrar(5639): resetting backoff for com.PushApplication
12-27 17:27:21.520: V/GCMRegistrar(5639): Saving regId on app version 1
12-27 17:27:21.520: D/WLDroidGap(5639): Registered at the GCM server with registration id APA91bEGLOHqoQHlmmb-wLCEzKFxrW2UHKaeMWnheA8nebNXNojI6O7o3B4BOnAc_tFXe8H3rsg6g4JH3mQl2vh5p8DxXbNhHgiSts-q2HFYFAT1l07Il-2QiRS0ypHLD4kGFQss0ueZWymkzOxypsFBQKPvezKq3Q
12-27 17:27:21.520: D/WLDroidGap(5639): Successfully registered to GCM notification service with token id APA91bEGLOHqoQHlmmb-wLCEzKFxrW2UHKaeMWnheA8nebNXNojI6O7o3B4BOnAc_tFXe8H3rsg6g4JH3mQl2vh5p8DxXbNhHgiSts-q2HFYFAT1l07Il-2QiRS0ypHLD4kGFQss0ueZWymkzOxypsFBQKPvezKq3Q
12-27 17:27:21.520: V/GCMBaseIntentService(5639): Releasing wakelock
12-27 17:27:24.030: E/PushApplication(5639): Cannot register to event source callback with existing alias: myPush
12-27 17:28:15.890: D/PushApplication(5639): Request [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications]
12-27 17:28:16.140: D/PushApplication(5639): response [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications] success: /*-secure-
12-27 17:28:16.140: D/PushApplication(5639): "isSuccessful":true*/
12-27 17:28:16.170: D/dalvikvm(5639): GC_FOR_ALLOC freed 321K, 5% free 7957K/8340K, paused 15ms, total 16ms
12-27 17:28:23.520: D/PushApplication(5639): Request [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications]
12-27 17:28:23.630: D/PushApplication(5639): response [http://192.168.48.69:8080/apps/services/api/PushApplication/android/notifications] success: /*-secure-
12-27 17:28:23.630: D/PushApplication(5639): "isSuccessful":true*/

【问题讨论】:

您是在推送通知示例应用程序上还是在您自己的应用程序中尝试这个?还要确保您的网络没有阻止 Google 要求的任何端口。 是的,我正在推送通知示例代码中尝试这个 为我工作...请参阅下面的答案。 我看到你添加了日志;还从 application-descriptor.xml 添加 android 元素。还要提及您在 Google 的 GCM 控制台中创建的 senderId 类型。可能是您使用了错误的类型或其他原因。您还可以删除本机文件夹(本机,而不是整个 android 文件夹)和 bin 文件夹并将工作灯项目上传到保管箱(将 senderid 和 gcm 键保留在描述符中,以便我可以检查它们) 当您尝试使用时会发生什么:senderId=390717241217 和 API Key=AIzaSyBm0fma2RWXhF0SMbvwZ5N1lwUghgCT95I --- 我认为您需要使用“浏览器密钥”而不是“服务器密钥”。试试我的,如果可行,请创建您自己的“浏览器密钥”。请参阅此处的“浏览器密钥”文档:developers.google.com/console/help/new/#generatingdevkeys 【参考方案1】:

我已在运行 Android 4.3 的 AVD 上成功使用推送通知示例应用程序。

工作灯设置:

    导入样本 将application-descriptor.xml 中的API KeysenderId 替换为来自Google GCM 控制台的API KeyProject Number 注意:对于 API 密钥,请确保您生成 浏览器密钥 (Google documentation)

    yourApp\android\native\AndroidManifest.xml 行中添加了android:targetSdkVersion="18"

    &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /&gt;

    构建并部署应用和适配器

    右键生成的Android项目>属性>Android,将Build Target改为Android 4.3

AVD 设置:

    确保在 Android SDK 管理器中,您已从 Extras 部分安装了 Google Cloud Messaging for Android LibraryGoogle Play services 确保为您在 AVD 中使用的 API 级别安装适当的 Google API 确保为您在 AVD 中使用的 API 级别安装 Android 映像

    确保将此 Google API 用作您的 AVD 的 Target

之后我有:

    在 AVD 中启动应用程序 使用“idan”登录 点击了“订阅”按钮 确保我确实已订阅(“isSubscribed”按钮)并且能够接收通知(“isPushSupported”按钮) 右键单击 PushAdapter 文件夹并选择 Run As &gt; Invoke Worklight Procedure 使用的参数:"idan","test message"

当应用程序打开(显示预期的警报)和关闭(通知显示在通知栏中。点击它打开应用程序并在登录后显示预期的警报时,AVD 中都会收到通知)。

【讨论】:

我尝试了您解释的方式,但没有奏效。今天我会再试一次,谢谢

以上是关于IBM Worklight 5.0.6.1 - Android 通知未到达设备或模拟器的主要内容,如果未能解决你的问题,请参考以下文章

IBM Worklight 5.0.6.1 - iOS 7 中的底部空白

IBM Worklight 5.0.6.1 - Android 通知未到达设备或模拟器

IBM Worklight 5.0.6.1 - 安装 5.0.6.1 修订包后,Studio 版本为 v6.0 而不是 v5.0.6.1

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

IBM Worklight 5.0.6.1 - 移动浏览器模拟器 - 用于 navigator.network.connection.type 与 navigator.connection.type

IBM Worklight 6.0.0.1 - 将适配器部署到服务器时出错