Questions tagged [google-cloud-messaging]

Google Cloud Messaging is a service to allow data to be sent remotely to Android and iOS applications and Chrome extensions and packaged apps.

Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits the reliable and scalable GCM infrastructure, plus new features! See the FAQ to learn more. If you are integrating messaging in a new app, start with FCM. GCM users are strongly recommended to upgrade to FCM, in order to benefit from new FCM features today and in the future. See the FCM tag.

Google Cloud Messaging (GCM) is a free service that enables developers to send messages between servers and client apps. This includes downstream messages from servers to client apps, and upstream messages from client apps to servers. The GCM service handles all aspects of queueing of messages and delivery to client applications running on target devices, and it is completely free.

The service provides a simple, lightweight mechanism that servers can use to tell mobile applications to contact the server directly, to fetch updated application or user data. The service handles all aspects of enqueuing of messages and delivery to the target application running on the target device.

The free service has the ability to send a lightweight message informing the Android application of new data to be fetched from the server. Larger messages can be sent with up to 4 KB of payload data. Each notification message size is limited to 1024 bytes, and Google limits the number of messages a sender sends in aggregate, and the number of messages a sender sends to a specific device.

For example, a lightweight downstream message could inform a client app that there is new data to be fetched from the server, as in the case of a "new email" notification. For use cases such as instant messaging, a GCM message can transfer up to 4kb of payload to the client app. The GCM service handles all aspects of queueing of messages and delivery to and from the target client app.

Send messages from the cloud

Send a message using GCM HTTP connection server protocol:

  https://gcm-http.googleapis.com/gcm/send
  Content-Type:application/json
  Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
  {
    "to": "/topics/foo-bar",
    "data": {
      "message": "This is a GCM Topic Message!",
     }
  }

Handle a downstream message on an Android device:

  @Override
  public void onMessageReceived(String from, Bundle data) {
     String message = data.getString("message");
     Log.d(TAG, "From: " + from);
     Log.d(TAG, "Message: " + message);
     // Handle received message here.
  }
7283 questions
31
votes
5 answers

Implement Firebase inside of a Library

I want to implement Firebase notifications system inside a library that I want to use as SDK in many apps. Firebase is asking now for an App ID, but I'm implementing it inside a library, thus no App Id. How could I achieve my goal to be able to send…
31
votes
7 answers

Clicking on Notification is not starting intended activity?

I am using GCM in my application and also using NotificationManager to Create a Notification whenever GCM message is received.Till now everything is working perfectly and GCM message is showing correctly in Notification area, but when I click on the…
Ansh
  • 2,366
  • 3
  • 31
  • 51
31
votes
3 answers

GCM: MulticastResult - which result is from which device?

Following the last section in the GCM: Getting Started guide, there's some book-keeping to be done after receiving the results. Quoting from the guide: It's now necessary to parse the result and take the proper action in the following cases: If…
Amir Uval
  • 14,425
  • 4
  • 50
  • 74
30
votes
1 answer

API key for GCM is suddenly invalid? Unauthorized (401) error

I created an Android API key for GCM Push Notification for my Android application.From the last two days, GCM server returns Unauthorized (401) response in PHP. Is there any reason for Android API key invalid/expire? Or Is Android API key…
30
votes
4 answers

Android GCM sent successfully but not received on some devices

On the server side, I am using GCM server 1.0.2 library provided by Google. On the client side, I set up GCM as provided on the official documentation. My problem is that everything works fine on most devices, but on few devices, push is not…
Jee Seok Yoon
  • 4,716
  • 9
  • 32
  • 47
30
votes
17 answers

How to fix Google Cloud Messaging Registration error: SERVICE_NOT_AVAILABLE?

I encountered a strange problem - I've been using GCM in my application for quite a long time and everything works perfectly. However, before a release to Google Play I changed my application package name from com.android.testapp to…
30
votes
6 answers

Cannot resolve symbol 'GoogleCloudMessaging' GCM

I am trying to get GCM working in my app (to notify users when our hours change, or when we have any promos going on), but I keep getting the error Cannot resolve symbol 'GoogleCloudMessaging' when trying to use the Google Cloud Messaging API. I am…
30
votes
13 answers

Google GCM server returns Unauthorized Error 401

I am using GCM services to push information from server. If I use browser key it shows the sucess mesaage as :…
Sushil Kandola
  • 870
  • 2
  • 9
  • 22
29
votes
5 answers

Get value from RemoteMessage from FCM onMessageReceived method

I have migrate gcm to fcm for push notification message. but how I Get bundle data from RemoteMessage received onMesssageReceived method. Old GCM give bundle data onMessageReceiced method but in FCM there is RemoteMessage data. So please tell me…
29
votes
2 answers

Why do I need to add the configuration file to my project to set up GCM correctly?

https://developers.google.com/cloud-messaging/android/client I've read this article. And it says that I need to download and add the configuration file to my project. But they do not explain, why should I do this? Won't it work without adding the…
Semyon Tikhonenko
  • 3,872
  • 6
  • 36
  • 61
29
votes
2 answers

What is authorizedEntity? Can't find gcm_defaultSenderId in own app

I am trying to get my app running with Google Cloud Messaging. I am following the Google Cloud Messaging Quickstart App which can be found here on github. In their quickstart app at some point we ask the Google Cloud Messaging service for a…
sitting-duck
  • 961
  • 1
  • 10
  • 22
28
votes
7 answers

Multiple Notifications Getting Delivered From GCM

I am using PHP to send Notifications on multiple android devices at a time. All registration ids are unique, following is the CURL request that I am sending. $url='https://android.googleapis.com/gcm/send'; $headers = array( …
vkj
  • 537
  • 4
  • 11
28
votes
3 answers

When do GCM Tokens Expire and What is the InstanceID?

Since GCM keeps getting updated, most of the resources I have searched seem outdated or unclear. Basically, I am confused over when the tokens and ID's expire. (For reference, I am working with Android.) From what I understand (and please correct me…
B. Roth
  • 359
  • 1
  • 3
  • 12
28
votes
8 answers

iOS support for Google Cloud Messaging

I saw in google's developer console that GCM allows to generate a API key for iOS. I searched in the web for any kind of documentation about how to implement Push Notifications through GCM in an iOS App, but i didn't find answers. Is it really…
28
votes
9 answers

Android GCM basic implementation

UPDATE: I fixed the problems in the code below so this makes a nice basic working example of how to use GCM So, I'm trying to implement Android GCM into my app. Here are the relevant parts I've added to the manifest:
Rooster242
  • 911
  • 3
  • 10
  • 19