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
41
votes
8 answers

GCM 'Error : Not Registered'

I succeed in testing My GCM code. But exactly same code, I couldn't get GCM push and got: GCM Error : Not Registered.
LKM
  • 2,410
  • 9
  • 28
  • 53
40
votes
4 answers

Xiaomi does not receive notification when application is not running

I am working on an application where I am using Google Push Notification. Application receives notification when it is running in Xiaomi phone otherwise when it's killed it does not receive notification. If we want to receive notification if…
N Sharma
  • 33,489
  • 95
  • 256
  • 444
40
votes
5 answers

Google Cloud Messaging - messages sometimes not received until network state changed

While working on a little project that integrates with GCM, I've stumbled across a bit of a strange issue. Some times when I start watching the log to see if messages are received, messages do not appear to be coming through until I have changed the…
Seidr
  • 4,946
  • 3
  • 27
  • 39
39
votes
6 answers

Send push notifications from server with FCM

Recently I asked a question on sending push notifications using GCM: Send push notifications to Android. Now that there is FCM, I am wondering how different it would be from the server side development. Coding wise, are they the same? Where can I…
user3573403
  • 1,780
  • 5
  • 38
  • 64
38
votes
6 answers

FCM background notifications not working in iOS

I have a problem with FCM notification on iOS. I receive notifications with success when my app is in foreground (the callback didReceiveRemoteNotification in appdelegate is fired), but I don't receive notifications when the app is in background (I…
38
votes
4 answers

Does Firebase Cloud Messaging support VOIP pushkit services?

Does anyone has an idea about Firebase Cloud Messaging support VOIP pushkit services. If yes then can someone please do provide guidelines for same. Same thing which is implemented in Skype / Hangout / WhatsApp or any other VOIP based apps. Thanks…
Hasya
  • 9,792
  • 4
  • 31
  • 46
37
votes
4 answers

How to group android notifications like whatsapp?

I don´t know how to group two or more notifications into only one and show a message like "You have two new messages".
37
votes
13 answers

GCM http 401 authorization error

When my backend server sends post requests to GCM servers I get an authorization error HTTP 401. I followed the steps described here: http://developer.android.com/google/gcm/http.html#auth_error >> api_key=AIzaSyDEy3... >> curl --header…
36
votes
3 answers

How to get Application from Context

Is there a way I can get application from Context. I noticed that activity and service has getApplication() method but Context does not. Background: I am using/extending the GCMBaseIntentService and the protected abstract void onMessage (Context…
Snake
  • 14,228
  • 27
  • 117
  • 250
35
votes
1 answer

GCM push notification works after app Force Stop?

I have used GCM to get push notifications, now if I Force stop the app from the settings on the Android device, will it be able to get push notifications? I have read many posts that say in this case an app cannot receive notifications. Is there…
Yagnesh
  • 1,123
  • 3
  • 17
  • 27
34
votes
0 answers

FCM Vs GCM? Why we need to migrate from GCM to FCM

Hello Friends I am new to this stackoverflow community, but have wide experience in developing code using various programming languages like android. Today I was implementing GCM with one of my application, I was facing some problem of delay in push…
34
votes
5 answers

How to avoid delay in Android GCM messages / change heartbeat

I've been reading many posts regarding a GCM issue that affects some people. It seems that in some devices/routers/carriers the notifications suffer delays. I've experienced this issue with my router: messages came with a lot of delay on WIFI but…
33
votes
1 answer

What is the difference between Firebase push-notifications and FCM messages?

Heloo, I am building an app where I am using push notifications via Firebase Console. I want to know what is a difference between simply push-notification and cloud message? Is it that messages from cloud messaging are data messages(have key and…
32
votes
3 answers

clear Recent apps wipe the apps memory and my receiver stopped working

MyApp's Receiver is just working fine if it in background which is: public class MySmsReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { System.out.println("triggered…
32
votes
2 answers

When will InstanceIDListenerService be called and how to test it?

With the last changes to Android GCM now a InstanceIDListenerService is provided to be able to listen to token refreshes by overriding the onTokenRefresh method. But when will this method be called? And is there any way to test it manually?
Eylen
  • 2,617
  • 4
  • 27
  • 42