We are developing a cordova based android application which has chat capability. We are sending test chat messages from a server and we received the messages just fine when the app is in foreground.
We would like to get a notification about chat message when app is in background. However we are not getting any Push Notification about chat message.
The steps we followed are mentioned below. Kindly let us know the mistake we're making.
We have referred this link to get notification on device when app is in background.
We use cordova PushPlugin to register device for push notification. And register device using below code
pubnub.mobile_gw_provision ({
device_id: 'A655FBA9931AB',
op: 'add',
gw_type: 'gcm', // or 'apns'
channel: 'my_chat',
callback: mySuccessCallback,
error: myErrorCallback,
});
We get the Push Notification if we programmatically send use the GCM device id to send Push notification from our server using GCM API.
We receive notification alert from pubnub in onNotificationGCM method of PushPlugin when application is in foreground.
We have also configured GCM server API key in admin console and enabled pubnub push notification.
I am using below Python code to publish the Chat:
_pubnub = Pubnub(publish_key='our-publish-key',
subscribe_key='our-sub-key')
channel_name = 'here-is-channel-string'
data=dict(
pn_gcm=dict(data=dict(
title_for_mobile='PN',
summary_for_mobile=['Hi, test']
)
),
text='what is your dob?',
sender=dict(name='Jon Snow', id='yyyyyyyy'),
meta=dict(job=dict(id='zzzzzzzz'))
)
_pubnub.publish(channel_name, data)
Getting push notification of incoming chat message when application is in background is a key functionality of my application.
Please let me know what I am doing wrong?