GCM Push notification not working when App is no l

2019-05-05 06:01发布

问题:

I am implementing GCM push notification service, for that I used Service class to extend my class. So Service that I implemented is running in background continuously. But I am not getting any notification when app is idle for long time.It is working only for, when app is running in stack.

I know, we cannot get notification when App is close from Stack.

Please help me to get notification when app is not running for long time (like Whatsapp or Gmail).

I used IntentService but it is working only when app is running(foreground or background).

回答1:

Read this, IntentService stops itself when it runs out of work.

and about notification it may be comes at any time for that you need to put BroadcastReceiver.

Create service class by extends Service : Tutorial about Service



回答2:

It's hard to say what exactly you are doing and what your code is. I would recommend you download Google's GCM sample here: https://github.com/googlesamples/google-services/tree/master/android/gcm

Get that to work first (just use your server to push the push to the app).

Then you can just implement that boiler plate code in your own app and it should work as expected.

Hope that helps.