Search code examples
androidpush-notificationibm-mobilefirst

receive GCM push without WLClient::connect()


Can we WLPush::subscribe() without WLClient::connect()?

Background
I'm working on an Android native application (offline version - App can work in case of no Internet) using the IBM Worklight framework, and I am implementing push notification. As I understand, we need WLPush::subscribe() in order to get the notification. But we cannot directly invoke the subscribe() method, it has to be in the Callback OnReadyToSubscribeListener. The listener will be invoked once connection is established.

The issue faced is:

  1. The app is registered to GCM
  2. The app was terminated
  3. A push notification is received in the device, I could already see the notification.

But I couldn't get the WLEventSourceListenerinvoked... because I need to connect before subscribe! This doesn't make any sense for me - because we have already have the notification shown in client console(DDMS).

I know that I could probably:

  • Override GCMIntentService
  • Force WLClient::connect() to trigger the TIMING

Can someone offer a better solution?

Updated on 31th October

I am using the "WL Android native push" sample project and found that it is impossible to get the callback WLEventSourceListener invoked without connect.

Steps to reproduce:

  1. Launch the sample client
  2. Click the "connect" to connect to server
  3. Connection returns successfully, click "subscribe" to subscribe
  4. In Eclipse IDE, right click the push adapter to send a push to client
  5. At client side, it receives the push message(shown on DDMS console log) and WLEventSourceListener is invoked.
  6. Kill the App
  7. Resend the push
  8. Push message is shown in the DDMS console log, and a notification in the notification bar.
  9. App is launched when the notification is clicked.
  10. The WLEventSourceListener get invoked when connect button is clicked again.

Here is the question. In step 9, the push message reaches the client, but in step 10, connect must be invoked to get WLEventSourceListener invoked. Is there a way to get the message without connect?


Solution

  • In order to subscribe for push notifications, the application is required to connect to the Worklight Server. So while the application can also work offline, it will need to, at least once, be "online" and go through the subscription process as it connects to the Worklight Server.

    The Worklight Server dispatches the notifications, which then go through Google's GCM service, which eventually sends it to the registered device.

    Then, it is the listener's purpose to pass the received notification to the application, open it and let the app logic to handle (display) it.

    Event source notifications are bound to a user - this is how the sample application provided by IBM is implemented - This means that only once the user has logged-in, the notification that was sent to that user will be displayed. Logging-in typically requires authenticating the user, which is done against the Worklight Server, which means a connection is required.

    For example, let us say that 2 users use the same device. User #1 received a notification, but user #2 is currently using the device. If user #2 will open the app w/out authentication, user #2 will receive the notification that was in fact sent for user #1.


    This brings up the following questions:

    1. What is the scenario of your application?
    2. Is authentication required in your case?

    If authentication is not required, then you need to look at the broadcast or tag notification types. These notification types will allow for the callback to be invoked without the connection requirement .

    Note: for the above notification types, you must use at minimum Worklight 6.2.
    You can read more about these, here: http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/admin/c_push_notification.html