IBM Worklight - Sent push notification to Android

2019-09-03 04:02发布

问题:

I've downloaded the push notifications project from "Woklight getting started" and I've installed it in my device with the proper API key and senderId. I've deployed the adapter and it's working fine. Now I'm trying to do the test of sending push notifications to the device.

To log in the application I can use arbitrary values, am I right? Like Username="Santaclaus" and Password="cheese".

Then to invoke the adapter procedure by right-clicking the adapter > invoke procedure > specify username and message, in the username I will put "Santaclaus" and in the message "Blabla bla bla", am I correct?

The problem is that when I press the Run button, the Invocation Result of procedure: 'submitNotification' from the Worklight Server:

    {
   "isSuccessful": true,
   "result": "Notification sent to user :: Santaclaus"
}

and the console shows this error:

[AUDIT   ] CWWKG0016I: Starting server configuration update.
[AUDIT   ] CWWKG0017I: The server configuration was successfully updated in 0.010 seconds.
[AUDIT   ] CWWKT0017I: Web application removed (default_host): http://L3CDH3K.corp.capgemini.com:10080/PushNotifications/
[AUDIT   ] CWWKZ0009I: The application PushNotifications has stopped successfully.
[AUDIT   ] CWWKG0016I: Starting server configuration update.
[AUDIT   ] CWWKG0017I: The server configuration was successfully updated in 0.030 seconds.
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://L3CDH3K.corp.capgemini.com:10080/PushNotifications/
[AUDIT   ] CWWKZ0001I: Application PushNotifications started in 3.362 seconds.
[WARNING ] FWLSE0029W: Registration of application PushNotifications-android-1.0 to mediator occured more than once. [project PushNotifications]
[WARNING ] FWLSE0029W: Registration of application PushNotifications-android-1.0 to mediator occured more than once. [project PushNotifications]
[ERROR   ] FWLSE0094E: Error while attempting to invoke GCM service (for sender key starting with 'AIzaSyBb'), sending will not resume until server is restarted or application re-deployed [project PushNotifications]
[ERROR   ] FWLSE0093E: Failed to invoke Google GCM push service. [project PushNotifications]
GCM Service invocation failed (reason: Authentication has failed for sender key starting with 'AIzaSyBb')
[WARNING ] Authentication error: Unable to respond to any of these challenges: {}

and the LogCat shows:

01-02 10:15:27.873: D/PushNotifications(7609): wlclient init started
01-02 10:15:27.883: D/PushNotifications(7609): Read cookies: null
01-02 10:15:27.883: D/PushNotifications(7609): CookieMgr read cookies: {}
01-02 10:15:27.933: W/PushNotifications(7609): Your application is using the WL.OptionsMenu API. Note that, if your application targets Android 3.0 (API level 11) or higher, WL.OptionsMenu might have no effect, depending on the device.
01-02 10:15:27.943: D/PushNotifications(7609): addDeviceIDHeader deviceIDSuccessCallback
01-02 10:15:27.963: D/PushNotifications(7609): connectOnStartup
01-02 10:15:27.973: D/PushNotifications(7609): connectOnStartup isCertificateExists:  false
01-02 10:15:28.473: D/PushNotifications(7609): Request [http://192.168.16.128:10080/PushNotifications/apps/services/api/PushNotifications/android/init]
01-02 10:15:28.563: D/CordovaActivity(7609): onMessage(spinner,stop)
01-02 10:15:30.983: D/SoftKeyboardDetect(7609): Ignore this event
01-02 10:15:31.083: D/dalvikvm(692): GC_CONCURRENT freed 448K, 8% free 8302K/8968K, paused 3ms+9ms, total 54ms
01-02 10:15:31.113: D/SoftKeyboardDetect(7609): Ignore this event
01-02 10:15:32.803: D/dalvikvm(490): GC_CONCURRENT freed 1668K, 18% free 15196K/18376K, paused 2ms+10ms, total 91ms
01-02 10:15:32.883: D/dalvikvm(692): GC_CONCURRENT freed 409K, 8% free 8280K/8968K, paused 3ms+3ms, total 29ms
01-02 10:15:37.473: D/dalvikvm(7544): GC_CONCURRENT freed 150K, 4% free 8393K/8700K, paused 3ms+2ms, total 22ms
01-02 10:15:37.513: D/Finsky(7544): [1] 5.onFinished: Installation state replication succeeded.
01-02 10:15:38.883: D/SoftKeyboardDetect(7609): Ignore this event
01-02 10:15:38.923: W/IInputConnectionWrapper(7609): getTextBeforeCursor on inactive InputConnection
01-02 10:15:38.923: W/IInputConnectionWrapper(7609): getTextAfterCursor on inactive InputConnection
01-02 10:15:39.003: D/SoftKeyboardDetect(7609): Ignore this event
01-02 10:15:40.023: I/GetJar SDK [com.zeptolab.ctr.ads](2538): CommManager checkManifestFile started
01-02 10:15:40.023: W/GetJar SDK [com.zeptolab.ctr.ads](2538): [OPTIONAL] Could not find the com.getjar.sdk.rewards.GetJarReceiver defined inside AndroidManifest.xml. It is required if there is no other implementation of Google Play billing.
01-02 10:15:40.053: I/GetJar SDK [com.zeptolab.ctr.ads](2538): AuthFlow: ensureAuthInternal() state:STARTING
01-02 10:15:40.053: I/GetJar SDK [com.zeptolab.ctr.ads](2538): AuthFlow: ensureAuthInternal() [running auth-flow]
01-02 10:15:40.053: I/GetJar SDK [com.zeptolab.ctr.ads](2538): AuthFlow: ensureAuthInternal() finishing with state:EXPIRY_CHECKING
01-02 10:15:40.133: D/dalvikvm(2538): GC_CONCURRENT freed 5953K, 20% free 25539K/31648K, paused 4ms+4ms, total 72ms
01-02 10:15:40.133: D/dalvikvm(2538): WAIT_FOR_CONCURRENT_GC blocked 39ms
01-02 10:15:44.163: D/PushNotifications(7609): Request [login]
01-02 10:15:44.243: D/SoftKeyboardDetect(7609): Ignore this event
01-02 10:15:44.373: D/PushNotifications(7609): Request [http://192.168.16.128:10080/PushNotifications/apps/services/api/PushNotifications/android/init]
01-02 10:15:48.043: D/dalvikvm(7609): GC_CONCURRENT freed 336K, 7% free 8328K/8864K, paused 2ms+2ms, total 32ms
01-02 10:15:49.433: D/PushNotifications(7609): Request [http://192.168.16.128:10080/PushNotifications/apps/services/api/PushNotifications/android/init]
01-02 10:15:49.463: W/InputMethodManagerService(490): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4186d4c0 attribute=null, token = android.os.BinderProxy@41af16b8
01-02 10:15:49.723: D/PushNotifications(7609): Clearing notification subscriptions.
01-02 10:15:49.723: D/PushNotifications(7609): Updating notification subscriptions.
01-02 10:15:49.723: D/WLDroidGap(7609): unregisterReceivers:Receiver not registered: null
01-02 10:15:49.723: D/WLDroidGap(7609): unregisterReceivers:Receiver not registered: null
01-02 10:15:49.733: V/GCMRegistrar(7609): Registering receiver
01-02 10:15:49.733: D/GCMRegistrar(7609): resetting backoff for com.PushNotifications
01-02 10:15:49.753: V/GCMRegistrar(7609): Registering app com.PushNotifications of senders 515493207294
01-02 10:15:49.753: W/PluginManager(7609): THREAD WARNING: exec() call to Push.subscribe blocked the main thread for 24ms. Plugin should use CordovaInterface.getThreadPool().
01-02 10:15:49.763: D/PushNotifications(7609): response [http://192.168.16.128:10080/PushNotifications/apps/services/api/PushNotifications/android/init] success: /*-secure-
01-02 10:15:49.763: D/PushNotifications(7609): {"WL-Authentication-Success":{"wl_remoteDisableRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null"},"PushAppRealm":{"userId":"Santaclaus","attributes":{},"isUserAuthenticated":1,"displayName":"Santaclaus"},"wl_antiXSRFRealm":{"userId":"35rkplsu96msjk6hichq990k2h","attributes":{},"isUserAuthenticated":1,"displayName":"35rkplsu96msjk6hichq990k2h"},"wl_deviceNoProvisioningRealm":{"userId":"05282bf4-9fe4-3c40-8280-3e627db3fe5c","attributes":{"mobileClientData":"com.worklight.core.auth.ext.MobileClientData@eb49d"},"isUserAuthenticated":1,"displayName":"05282bf4-9fe4-3c40-8280-3e627db3fe5c"}},"userPrefs":{},"notificationSubscriptionState":{"eventSources":[{"eventSource":"PushEventSource","alias":"myPush","adapter":"PushAdapter"}],"token":"APA91bFg1hMAQcCZnLHRQ5qIZu5HdkcWpt0p99cftqXD4YrrxD8W-F5r7x3DYRGv-hY0jFTvtg5Yg9Uo1o_EjJFxkoyLUKGxNiRzmh-md9-FwCQ2gfSvTVFT1Vt6J9UigpwdWFCblB-dBBYv4U9Z2S3Vi5gvBFr9WPUwDQGR2Ez5GfQQiYj3x1k"},"gadgetProps":{"directUpdate":{"updateUnpackedSize":1187754,"availableSkins":["default"],"checksum":796238133,"updateSize":385169},"ENVIRONMENT":"android"},"userInfo":{"wl_authenticityRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_remoteDisableRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null"},"PushAppRealm":{"userId":"Santaclaus","attributes":{},"isUserAuthenticated":1,"displayName":"Santaclaus"},"wl_antiXSRFRealm":{"userId":"35rkplsu96msjk6hichq990k2h","attributes":{},"isUserAuthenticated":1,"displayName":"35rkplsu96msjk6hichq990k2h"},"wl_deviceAutoProvisioningRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_deviceNoProvisioningRealm":{"userId":"05282bf4-9fe4-3c40-8280-3e627db3fe5c","attributes":{"mobileClientData":"com.worklight.core.auth.ext.MobileClientData@eb49d"},"isUserAuthenticated":1,"displayName":"05282bf4-9fe4-3c40-8280-3e627db3fe5c"},"myserver":{"userId":"Santaclaus","attributes":{},"isUserAuthenticated":1,"displayName":"Santaclaus"},"wl_anonymousUserRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null}}}*/
01-02 10:15:49.763: D/PushNotifications(7609): wlclient connect success
01-02 10:15:49.773: D/PushNotifications(7609): before: app init onSuccess
01-02 10:15:49.783: D/PushNotifications(7609): after: app init onSuccess
01-02 10:15:49.783: D/PushNotifications(7609): added onPause event handler 
01-02 10:15:49.783: D/PushNotifications(7609): wlclient init success
01-02 10:15:49.913: D/dalvikvm(929): GC_CONCURRENT freed 408K, 8% free 8984K/9664K, paused 3ms+2ms, total 25ms
01-02 10:15:49.993: V/GCMBroadcastReceiver(7609): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-02 10:15:49.993: V/GCMBroadcastReceiver(7609): GCM IntentService class: com.PushNotifications.GCMIntentService
01-02 10:15:49.993: V/GCMBaseIntentService(7609): Acquiring wakelock
01-02 10:15:50.003: V/GCMBaseIntentService(7609): Intent service name: GCMIntentService-515493207294-1
01-02 10:15:50.003: D/GCMBaseIntentService(7609): handleRegistration: registrationId = APA91bFg1hMAQcCZnLHRQ5qIZu5HdkcWpt0p99cftqXD4YrrxD8W-F5r7x3DYRGv-hY0jFTvtg5Yg9Uo1o_EjJFxkoyLUKGxNiRzmh-md9-FwCQ2gfSvTVFT1Vt6J9UigpwdWFCblB-dBBYv4U9Z2S3Vi5gvBFr9WPUwDQGR2Ez5GfQQiYj3x1k, error = null, unregistered = null
01-02 10:15:50.003: D/GCMRegistrar(7609): resetting backoff for com.PushNotifications
01-02 10:15:50.003: V/GCMRegistrar(7609): Saving regId on app version 1
01-02 10:15:50.023: D/WLDroidGap(7609): WLGCMIntentService: Registered at the GCM server with registration id APA91bFg1hMAQcCZnLHRQ5qIZu5HdkcWpt0p99cftqXD4YrrxD8W-F5r7x3DYRGv-hY0jFTvtg5Yg9Uo1o_EjJFxkoyLUKGxNiRzmh-md9-FwCQ2gfSvTVFT1Vt6J9UigpwdWFCblB-dBBYv4U9Z2S3Vi5gvBFr9WPUwDQGR2Ez5GfQQiYj3x1k
01-02 10:15:50.023: V/GCMBaseIntentService(7609): Releasing wakelock
01-02 10:15:50.943: W/InputMethodManagerService(490): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@419c5618 attribute=null, token = android.os.BinderProxy@41af16b8
01-02 10:15:52.613: D/PushNotifications(7609): Request [http://192.168.16.128:10080/PushNotifications/apps/services/api/PushNotifications/android/notifications]
01-02 10:15:52.623: D/WLDroidGap(7609): Push.dispatch(): method=WL.Client.Push.__onmessage
01-02 10:15:52.793: D/PushNotifications(7609): response [http://192.168.16.128:10080/PushNotifications/apps/services/api/PushNotifications/android/notifications] success: /*-secure-
01-02 10:15:52.793: D/PushNotifications(7609): {"errors":[],"isSuccessful":true,"warnings":[],"info":[]}*/
01-02 10:15:55.593: W/InputMethodManagerService(490): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41b721e8 attribute=null, token = android.os.BinderProxy@41af16b8

This is the android element from application-descriptor.xml file:

 <android securityTest="PushApplication-strong-mobile-securityTest" version="1.0">
        <worklightSettings include="true"/>
        <pushSender key="AIzaSyBb08MeW5jlh9bDSlpqHsgGgknT6QHiWn4" senderId="515493207294"/>
        <security>
            <encryptWebResources enabled="false"/>
            <testWebResourcesChecksum enabled="false" ignoreFileExtensions="png, jpg, jpeg, gif, mp4, mp3"/>
            <publicSigningKey>Replace this text with the actual public signing key of the certificate used to sign the APK, available by using the 'Extract public signing key' wizard.</publicSigningKey>
        </security>
 </android>

I've created a browser key from Google Cloud Console. I've created an android key in first place, I don't know which should I use. In this case I used the browser key specifying the referers as follows:

0E:30:5F:3A:A0:D9:A5:41:EF:FB:08:1B:7A:AC:0B:92:E1:C7:E8:33;com.PushNotifications

The device OS version is android 4.2.1 I'm using the last version available of Worklight Developer Edition. Have you any idea how to make it works?

Thanks.

回答1:

Follow the set-up instructions as provided here: IBM Worklight 5.0.6.1 - Android notification does not reach either device or emulator

  • The emulator instructions are not relevant in your case
  • When creating the browser key, simply do Create New Key > Browser Key > Create.
  • Do not edit it afterwards, i.e. do not add anything in the "Accept requests..." section. In your question you mention that you do this - undo it.