IBM Worklight 5.0.6.1 - Android notification does

2019-01-15 23:12发布

问题:

I followed all steps as given in the Push Notifications training module, as well as in this Stack Overflow question: IBM Worklight - Push Notifications feature does not work in Android emulator

When I send a message using the PushBackendEmulator or by calling the PushAdapter procedure from URL it says message sent successfully, but the notification is not received in either device or emulator and there is no error in LogCat.

I am using a device running Android OS 4.3 and AVD running Android OS 4.0.3.
I am trying this with the Push Notification Getting Started training module sample.

In application-descriptor.xml, I have set:

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

senderID is the project number:

and the key is taken from Google APIs Console : by Create new Server Key option

When I run the App on device and execute push adapter to send push message then the Eclipse Studio console gives below exceptions:

[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)

and LogCat shows:

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}*/

回答1:

I have successfully used the Push Notifications sample application on an AVD running Android 4.3.

Worklight setup:

  1. Imported the sample
  2. Replaced the API Key and senderId in application-descriptor.xml with the API Key and Project Number from the Google GCM console
    • Note: for API Key make sure you generate a browser key (Google documentation)
  3. Added android:targetSdkVersion="18" in yourApp\android\native\AndroidManifest.xml in the line:

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />

  4. Built and deployed the app and adapter

  5. Right-clicked the generated Android project > Properties > Android and changed the Build Target to Android 4.3

AVD setup:

  1. Make sure that in the Android SDK Manager you have installed from the Extras section both the Google Cloud Messaging for Android Library as well as Google Play services
  2. Make sure to install the appropriate Google APIs for the API Level you are using in your AVD
  3. Make sure to install the Android image for the API Level you are using in your AVD
  4. Make sure to use this Google API as the Target for your AVD:

After that I have:

  1. Launched the app in the AVD
  2. Logged in with "idan"
  3. Tapped the "Subscribe" button
  4. Made sure I am indeed subscribed ("isSubscribed" button") and able to receive notifications ("isPushSupported" button)
  5. Right-clicked on the PushAdapter folder and chose Run As > Invoke Worklight Procedure
  6. Used the parameters: "idan","test message"

The notification was received in the AVD both when the app is open (the expected alerts were displayed) as well as closed (notification was displayed in the notification bar. Tapping it opened the app and after logging in the expected alerts were displayed).