IBM Worklight - Android push notification sent but

2019-09-15 08:33发布

问题:

I am new to IBM Worklight and I am trying to get push notification to work on my Android device.

I have followed the "Push notification in hybrid applications" tutorial on their website and imported the sample project.

The problem is somehow I didn't receive the push notification in my android device (haven't tried any other device yet). I didn't see any error in the console and it reported that the notifications has been sent to user.

Here is the log :

[2014-07-18 12:44:32]             Starting procedure invocation on Worklight Server 
[2014-07-18 12:44:33]             Not deploying adapter 'PushAdapter' since it was not changed since last deployment 
[2014-07-18 12:44:33]             Invoking procedure: 'submitNotification' of adapter 'PushAdapter' 
[2014-07-18 12:44:33]             Server host: 192.168.1.100 
[2014-07-18 12:44:33]             Server port: 10080 
[2014-07-18 12:44:33]             Parameters: ["david","test message"] 
[2014-07-18 12:44:33]             Procedure invocation finished

And this is the report body:

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

But I wait and wait and wait... and the notification still not arrived...

What I have done :

  • Read many SO question relevant to this topic like this and this (but still no luck)
  • Install Google Cloud Messaging Library for Android, although it has already obsolete, and Google Play services :
  • Generate API credential in google console (tried both browser key and android key)
  • Set key on application-descriptor.xml
  • Enable Google Cloud Messaging for Android and Google Play Android Developer API in google console project
  • turn off firewall
  • add google service lib as project reference

And i ran out of idea..

It seems my worklight console also didn't receive the push notification :

it shows 0 new messages and 0 total messages..

please help me.. i am losing hope.. any help would be very appreciated :) thanks in advance

回答1:

Push Notifications in Worklight work for me when following the below instructions:

  1. Installed Worklight Studio v6.2 from the Eclipse Marketplace
  2. Downloaded and imported the Push Notifications sample project
  3. Used my GCM ID and GCM Key in application-descriptor.xml

    • The GCM ID is the "project number". You can find it once logging into the GCM Console and into the project you create
    • The GCM Key is the "Browser" key you create in your GCM project under Credentials > Create key

  4. Setup the Android SDK with Google API level 19 & Google Play Services
  5. Created an AVD using the Google API (not to be confused with Android 4.4.2 level 19)

    • This is especially important: when testing in the Android Emulator you need to use the Google API and not the Android API
    • When testing in a physica device, you can use the Android API

  6. Right-click on the adapter folder > Run As > Deploy Worklight Adapter
  7. Right-click on the application folder > Run As > Run on Worklight Development Server
  8. Right-click on the generated Android project > Run As > Android application

  9. The AVD launches, application is installed

  10. Logged-in with "Idan"
  11. Right-click on the adapter folder > Invoke Worklight Adapter
  12. Entered 'Idan','test notification' and clicked on the OK button

In the device, the alert()s from the application's JavaScript start popping, indicating the notification was received.

The above was tested in my home network, so I would suggest to double-check that you followed the above as well as check again your network settings. Take a look at slide #53 in the Push Notifications training module.