0

I looking for a way to read notification message automatically, and displaying it, on receiving a message from the server, when the activity is on the foreground, just like a chat application.

I got GCM working, and i am able to create a notification when the client app receives a message from the server.

anyone guide me how to get this done?

6119
  • 99
  • 8

1 Answers1

0

If I understand your question when the server send the device a message and your application on foreground u want to get the message into your application and avoid from create a notification.

when you get a call to your GCM Receiver you should know if your application is on the foreground. look here for know if the application in background/foreground.

now, if the application on background create notification else don't :)

hope it's help u.

Community
  • 1
  • 1
Liran Peretz
  • 580
  • 8
  • 11
  • I am extending IntentService, should i do this check in HandleIntent()? – 6119 Nov 11 '14 at 12:50
  • u are talking about the receiver? – Liran Peretz Nov 11 '14 at 13:12
  • yeah from there i'm creating a notification, so could i make the checking there? a little more google-ing lead me to an example of LocalBroadcastManager. So, correct me if i'm wrong, i could check if the application is on the foreground, if so i could do a localbroadcast, else create a notification. – 6119 Nov 11 '14 at 13:25
  • first of all you should extends BroadcastReceiver for getting the message from GCM. and if the application on foreground u can to transfer the information with another receiver that, and your activity should register to this receiver. – Liran Peretz Nov 11 '14 at 15:39
  • Its working! I did it like u said, put the checking in BroadcastReceiver and use the LocalBroadcastManager to broadcast the message if the activity is on the foreground. Many thanks to you. :) – 6119 Nov 12 '14 at 06:50