Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broadcast a notification to all registered devices

I'm trying to add push notification using Google Cloud Messaging to my Android application. I don't need anything fancy, I just want to notify all users of the app when certain events happen.

I don't need to notify individual users, I always want to send the notification to every user. This is an internal app with a very limited number of users, it is not distributed publicly.

Now, as far as I understand the documentation I need a registration id for every notification I want to send. I don't really want to keep track of those as I don't need to identify individual devices.

  • Can I just broadcast to all devices without using any registration ids?
  • If not, how can I get the registration ids of all registered devices? Do I have to keep track of those manually (outside the GCM communication)?
like image 269
Mad Scientist Avatar asked Aug 27 '12 12:08

Mad Scientist


2 Answers

Can I just broadcast to all devices without using any registration ids?

No, sorry, not at the present time.

If not, how can I get the registration ids of all registered devices? Do I have to keep track of those manually (outside the GCM communication)?

Yes, you have to keep track of those manually (e.g., have the app send you the registration ID via a Web service).

like image 153
CommonsWare Avatar answered Sep 23 '22 01:09

CommonsWare


You can subscribe topic and send notification from server

Client :

 private void subscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);   
    pubSub.subscribe(token, "/topics/global", null);    
 }

Server :

   {"to": "/topics/global","notification":{"message":"testmessage"}}
like image 34
Arun Avatar answered Sep 23 '22 01:09

Arun