When i am sending a gcm message with notification(no data) payload, then the android notification is shown only if my app is in background. If the app is in foreground then
So it was possibility no. 3 "The behavior is like this only."
Here is the reply from gcm-dev-support@google.com :
This is to confirm to you that the notification payload on Android will only show on the notification tray when the app is in the background. If it is in the foreground and you would like to deploy a notification, you could consider deploying notifications similarly to this method in the sample app. It is called from onMessageReceived(). Hope this helps.
In your Chat activity create a broadcast receiver like below and call it in the onCreate function.
Add variable BroadcastReceiver mRegistrationBroadcastReceiver; to your class
private void setUpBroadcastReceiver() {
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//create notification
}
};
}