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.
  }
7270 questions
498
votes
26 answers

google-services.json for different productFlavors

Update: GCM is deprecated, use FCM I'm implementing the new Google Cloud Messaging following the guides from the Google Developers page here I've successfully run and test it. But my problem now is I have different product flavors with different…
gentra
  • 5,336
  • 3
  • 13
  • 18
242
votes
15 answers

Error:Conflict with dependency 'com.google.code.findbugs:jsr305'

I created a new project in Android Studio 2.2 Preview 1 with Android App and Backend module with Google Messaging. This is the app file: apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.3" …
214
votes
13 answers

GCM with PHP (Google Cloud Messaging)

Update: GCM is deprecated, use FCM How can I integrate the new Google Cloud Messaging in a PHP backend?
196
votes
9 answers

How to send push notification to web browser?

I have been reading for past few hours about Push Notification API and Web Notification API. I also discovered that Google & Apple gives push notification service for free via GCM and APNS respectively. I am trying to understand if we can implement…
esafwan
  • 14,622
  • 30
  • 99
  • 154
183
votes
23 answers

INSTALL_FAILED_DUPLICATE_PERMISSION... C2D_MESSAGE

I am using Google notifications in my app, and until now I have done below in the manifest:
178
votes
11 answers

Google Play Services GCM 9.2.0 asks to "update" back to 9.0.0

So this morning I started updating to the latest version of my project libraries. I'm trying to update GCM to the latest version 9.2.0, but I get this error: Error:Execution failed for task ':app:processDebugGoogleServices'. Please fix the…
herrmartell
  • 2,827
  • 2
  • 14
  • 25
162
votes
11 answers

Where can I find the API KEY for Firebase Cloud Messaging?

I am trying to figure out how the new version of GCM or Firebase Cloud Messaging works so I moved one of my projects to the new Firebase console, If I did not have the API KEY or I want to create a new one... where can I do it?
Nissar
  • 2,052
  • 2
  • 10
  • 12
144
votes
4 answers

Firebase messaging, where to get Server Key?

Firebase allows us to send notification messages via our own application by making POST request. This tutorial, gives to us instructions how to make this request. However, there is Authorization field in header where I must to place my own Server…
Mr.D
  • 5,765
  • 8
  • 41
  • 95
135
votes
19 answers

Use different GoogleService-Info.plist for different build schemes

I am using a build scheme for prod and one for staging (with 2 different bundle identifiers) and I am trying to use a separate GoogleService-Info.plist for each scheme. Is there any way to manually select the plist file to use when initialising GCM…
nwaxgui
  • 1,351
  • 2
  • 7
  • 3
125
votes
3 answers

What does google-services.json really do?

I work on adding Google Analytics and GCM services to my current app. On the guide for both services implementation, google asks developer to generate a json file: google-services.json and put it under root directory of the app. I found that even…
98
votes
8 answers

FCM with AWS SNS

I am using AWS resources for my android project, I am planning to add push notification service for my project with AWS SNS.there are few questions bothering me much. I did not find any questions regarding these, except one or two but with unclear…
97
votes
4 answers

Android: Test Push Notification online (Google Cloud Messaging)

Update: GCM is deprecated, use FCM I am implementing Google Cloud Messaging in my application. Server code is not ready yet and in my environment due to some firewall restrictions I can not deploy a test sever for push notification. What I am…
90
votes
6 answers

Adding HttpClient headers generates a FormatException with some values

This occurred within the context of coding against Google Cloud Messaging, but applies elsewhere. Consider the following: var http = new HttpClient(); http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("key=XXX"); and var http…
Andrew
  • 2,305
  • 2
  • 20
  • 34
81
votes
10 answers

Android GCM SENDER_ID, how to get it?

I try to migrate to GCM and I have an issue with the SENDER_ID I need to provide. I use the demo project from google. In this project I need, if I understand this well, to provide a SENDER_ID to the application in the CommonUtilities.java file. The…
Zelter Ady
  • 5,924
  • 12
  • 44
  • 69
80
votes
15 answers

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM

Since I updated to Android SDK Tools 25.1.6 and Android Support Repository 32.0.0 (this morning), I got the following error, I didn't change anything in my code and it is still working on my colleague computer (Android SDK Tools 25.1.1 + Android…
1
2 3
99 100