How to force application to receive push notification in android?


#1

If user close app in android , then that app is no longer receive messages from GCM . So how to force app to receive push notification in android? Is there a way to start app again automatically like whatsapp.


#2

This is becoming a FAQ :slight_smile: …
When the app is not running the OS receives the notification and displays it to the user.
The app is then started when the user clicks the notification.

(BTW, WhatsApp is impossible to shut down, it is always running)


#3

Oh, and if you want your app to get notified directly (before the user clicks the status bar notification), you will need to patch the PushPlugin to add some stuff to the notificationIntent:

notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

…and then handle the result in the PushHandlerActivity class.


#4

When the app is not running notification are not showing up in notification bar . I want to know …is there any way to receive notification even if app is closed.


#5

You man need to look again at your notification system. Look here : http://devgirl.org/2013/07/17/tutorial-implement-push-notifications-in-your-phonegap-application/

I learned with this tutorial and my notifications are perfectly working when the app is closed.


#6

If there are no notifications showing when the app is closed you have some problem in how you are registering or sending them. Either the app is not registering itself properly when it is started, or you are not sending the notifications correctly.


#7

When the app is in background or running then only I get notifications. If I close then I don’t receive any notifications. I read it some where that It is android behavior.


#8

Does your notifications have a message property on the payload object?
It might be that nothing gets displayed if you have no message and no title.


#9

yes, For testing purpose I am sending same message from server . It is coming on my device only if my app is in background or foreground not then app is closed


#10

So when your app in in background, you get a status bar notification on the phone, but not when the app is closed?


#11

Yes you are right…


#12

Hmm… I can’t see how this can be happening. If your app is properly registered, which it must be as you are receiving notifications, then it is the OS that should be displaying the notifications!

Are you using the latest (v2.4.0) version of the plugin?

Oh, and you’re not de-registering the app when it closes, are you???


#13

Hi JesperWe ,
Thanks for being with this issue for so long. Finally I found problem. I was testing on MIUI OS ,In which I have to explicitly set “auto start” permission for app .
Now it is working perfectly :smile:


#14

So, today’s lesson for you: Always include all relevant information in your post when you make questions on forums… If you would have done that you could have gained much time.


#15

Please explain more about the auto start thing. Even I am facing the same issue.


#16

Found it here in miui site


#17

hate to re-open this as original poster’s solution was very specific to his case; but the replies added here do apply to my case.

i have exact same issue:

  • when app is running in foreground or background i get notices fine.
  • if i do a force stop of my app then i do not get notices showing up on notification bar

i do have message field filled in. I didn’t have a title in my msg but i added one and no help. I am using a Samsung Galaxay Tab 4 running Android 4.2.2 and i used the tutorial from devgirl posted above as the basis for my app code.

i am not sure if this is h/w dependent? i looked at a couple other apps, like FB Messenger… and found it would not allow me to stop it. Perhaps that is the trick around this?


#18

Hi guys,
Is it possible to get around this problem programmatically?


#19

Hello, I have tested this in an Asus Zenfone 2 and I had to set the auto start permission to allow the notification to be shown when the app is closed. Is there any way to request this permission programatically when installing the app?