1
votes

I am testing the sample project for gcm notification from google https://developers.google.com/cloud-messaging/android/start

This project is using com.google.android.gms:play-services-gcm:9.0.0

After I install the app to my phone via android studio. I kill the app from my phone(not force kill from setting). Then, I tried to send notification message according to google instruction.

Notification cannot show on my phone. When I check the logcat. I found the following log about GCM.

06-08 11:19:37.859 5080-5080/? W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=gcm.play.android.samples.com.gcmquickstart (has extras) }

After that I launch the app in phone and kill the app again, then send GCM again to my phone. At that time, notification can show correctly in my phone. It seem, application need to restart one time for receiving gcm notification or application should be received notification before user kill the app.

How should I solve this problem? As I know, lower version of play-services-gcm:9.0.0 do not have this kind of problem.

4

4 Answers

1
votes

It's a feature of the Android platform. Force stopping an application by the user puts the application in a stopped state and none of its code is run, including any broadcast receivers declared in manifest. Only when the user explicitly launches the app it is put in a state where the receivers get fired.

Read this thread

1
votes

EDIT: It maybe that you gym token doesn't have time to register with the server. Do you get a token and a registration confirmation from the server?

If your just starting with GCM then I would suggest to use FCM it is replacing GCM. https://firebase.google.com/docs/cloud-messaging/

Same thing but with support and new examples. It looks even easier to use than GCM.

1
votes

When I installed the app by using apk file, this problem is not happen. This problem is only happen when I install the app by running project in android studio. Thanks for all suggestion and answer.

0
votes

Best fix I have so far is to unplug the phone, kill the app, restart the app then kill it again. Doing this will have the notification displayed even after installing it via android studio. Here is another thread regarding the issue: https://code.google.com/p/android/issues/detail?id=219084