简体   繁体   中英

IBM Worklight - Push notification on Android

I am trying out the push notification for Android phones and tablets, and we are using the sample code given by IBM Worklight ( see blog post ).

We have registered with Google GCM and have got the project id and API key; the code works fine with tablets, but when i run the same with phone isSubscribed is returning false, Can anyone please test the code which is given here and let us know what is that we are doing wrong for it to not work in multiple devices.

LogCat from the first device - tablet running Android v3.2
Works fine.

08-06 17:48:35.110: V/webview(11093):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
08-06 17:48:40.930: V/webview(11093):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
08-06 17:48:40.950: D/PushApplication(11093): Request [http://172.20.10.8:8080/apps/services/api/PushApplication/android/notifications]
08-06 17:48:41.470: D/PushApplication(11093): response [http://172.20.10.8:8080/apps/services/api/PushApplication/android/notifications] success: /*-secure-
08-06 17:48:41.470: D/PushApplication(11093): {"errors":[],"isSuccessful":true,"warnings":[],"info":[]}*/
08-06 17:48:41.470: V/(11093): ResourceHandle
08-06 17:48:41.520: D/dalvikvm(11093): GC_CONCURRENT freed 331K, 6% free 7957K/8455K, paused 3ms+4ms
08-06 17:48:44.710: V/(11093): ResourceHandle
08-06 17:49:02.820: V/GCMBroadcastReceiver(11093): onReceive: com.google.android.c2dm.intent.RECEIVE
08-06 17:49:02.820: V/GCMBroadcastReceiver(11093): GCM IntentService class: com.PushApplication.GCMIntentService
08-06 17:49:02.820: V/GCMBaseIntentService(11093): Acquiring wakelock
08-06 17:49:02.830: V/GCMBaseIntentService(11093): Intent service name: GCMIntentService-804999789155-4
08-06 17:49:02.830: D/WLDroidGap(11093): Received a message from the GCM server
08-06 17:49:02.830: V/GCMBaseIntentService(11093): Releasing wakelock
08-06 17:49:02.840: D/WLDroidGap(11093): Queuing message for dispatch to javascript
08-06 17:49:02.840: D/WLDroidGap(11093): Dispatching to javascript Message(alert=got a new message, badge=1, sound=sound.mp3, payload={
08-06 17:49:02.840: D/WLDroidGap(11093):    "alias": "myPush",
08-06 17:49:02.840: D/WLDroidGap(11093):    "foo": "bar"
08-06 17:49:02.840: D/WLDroidGap(11093): })
08-06 17:49:02.840: D/PushApplication(11093): WL.Client.Push received notification for alias myPush

LogCat from the second device - tablet running Android v4.0.4
Subscribe button is disabled

01-01 10:02:31.740: V/webview(8635):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
01-01 10:02:31.840: V/GCMBroadcastReceiver(8635): onReceive: com.google.android.gcm.intent.RETRY
01-01 10:02:31.840: V/GCMBroadcastReceiver(8635): GCM IntentService class: com.PushApplication.GCMIntentService
01-01 10:02:31.840: V/GCMBaseIntentService(8635): Acquiring wakelock
01-01 10:02:31.850: V/GCMBaseIntentService(8635): Intent service name: GCMIntentService-804999789155-2
01-01 10:02:31.850: E/GCMBaseIntentService(8635): Received invalid token: 1101110000000111011000111110100011101100101100011101100111100011

we have removed the disabled from the sample code, which allows us to check if the tablet 2 is subscribed or not, the below logs shows clearly that the device is not subscribed.

01-01 10:27:13.440: V/webview(9400): NO_FAST_DRAW = false
01-01 10:27:13.640: V/webview(9400):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
01-01 10:27:13.660: E/PushApplication(9400): Can't subscribe, notification token is not updated on the server
01-01 10:27:20.840: V/GCMBroadcastReceiver(9400): onReceive: com.google.android.gcm.intent.RETRY
01-01 10:27:20.840: V/GCMBroadcastReceiver(9400): GCM IntentService class: com.PushApplication.GCMIntentService
01-01 10:27:20.840: V/GCMBaseIntentService(9400): Acquiring wakelock
01-01 10:27:20.860: V/GCMBaseIntentService(9400): Intent service name: GCMIntentService-804999789155-6
01-01 10:27:20.860: V/GCMRegistrar(9400): Registering app com.PushApplication of senders 804999789155
01-01 10:27:20.870: V/GCMBaseIntentService(9400): Releasing wakelock
01-01 10:27:23.340: V/GCMBroadcastReceiver(9400): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-01 10:27:23.340: V/GCMBroadcastReceiver(9400): GCM IntentService class: com.PushApplication.GCMIntentService
01-01 10:27:23.340: V/GCMBaseIntentService(9400): Acquiring wakelock
01-01 10:27:23.340: V/GCMBaseIntentService(9400): Intent service name: GCMIntentService-804999789155-7
01-01 10:27:23.340: D/GCMBaseIntentService(9400): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-01 10:27:23.340: D/GCMBaseIntentService(9400): Registration error: SERVICE_NOT_AVAILABLE

Please check your internet connectivity because the error you see in the log from your second device is :

01-01 10:27:23.340: V/GCMBaseIntentService(9400): Intent service name: GCMIntentService-804999789155-7
01-01 10:27:23.340: D/GCMBaseIntentService(9400): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-01 10:27:23.340: D/GCMBaseIntentService(9400): Registration error: SERVICE_NOT_AVAILABLE

This means you app is not able to register with GCM service to get the token, as GCM service seems to be unavailable, hence the error SERVICE_NOT_AVAILABLE, may be becuase of your internet connectivity issue or GCM might have been unavailable when you tried this. So try for few more times.

Also please note that, now you are running your app on another device which means you need to do the subscription again even though you log in as same user (as on first device).So isSubscribed() is right in returning false.

Subscribe call essentially means subscribe the logged in user on this particular device to given event source. Since you have not yet subscribed for this second device (even though the same user is subscribed on first device), isSubscribed() returns false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM