I'm developing an android application which will receive push notifications. I'd like to present those messages within app layout instead of standard android notification alert. Is it possible ? How can I achieve this?
Is it possible ?
That depends upon whether or not you have an "app layout" or not at the time the GCM message arrives. You do not control whether your UI exists at the time, as that is up to the user and the OS. You also do not completely control the timing of the GCM message delivery, as it can be influenced by things like available Internet access.
However, with GCM, there is no UI impact unless you cause that UI impact, whether that is via updating existing activities/fragments or raising a
Notification. A GCM message does not trigger a "standard android notification alert", unless you are the one raising that "alert".
How can I achieve this?
GCM messages reach your app's process via a
BroadcastReceiver. You can use an event bus (e.g., greenrobot's EventBus) to tell the rest of your process that the message arrived. If you have an activity/fragment that is in position to use that message, it can subscribe to the event bus and consume the message. If your
BroadcastReceiver determines that nobody consumed the message, then it can implement some sort of fallback behavior, like displaying a