phonegap-build / PushPlugin

This repository is deprecated head to phonegap/phonegap-push-plugin
https://github.com/phonegap/phonegap-plugin-push
MIT License
1.32k stars 999 forks source link

No notifications in android when the app is closed #85

Closed Chexpir closed 10 years ago

Chexpir commented 10 years ago

In GCMIntentService.java:73 we see they check if the app is in foreground

// Send a notification if there is a message and not in foreground if (!PushPlugin.isInForeground() && extras.getString("message").length() != 0) {

, but that #79 change doesn't work correctly in android due to the ActivityManager starts the app in the moment the notification is received, thus when the app is completely closed there is no notification.

10-08 11:56:16.042: I/ActivityManager(525): Start proc com.myapp.mainClass for broadcast com.myapp.mainClass/com.plugin.gcm.CordovaGCMBroadcastReceiver: pid=25076 uid=10112 gids={50112, 3003, 1028} 10-08 11:56:16.072: V/GCMBroadcastReceiver(25076): onReceive: com.google.android.c2dm.intent.RECEIVE 10-08 11:56:16.072: V/GCMRegistrar(25076): Setting the name of retry receiver class to com.plugin.gcm.CordovaGCMBroadcastReceiver 10-08 11:56:16.072: V/GCMBroadcastReceiver(25076): GCM IntentService class: com.plugin.gcm.GCMIntentService 10-08 11:56:16.082: V/GCMBaseIntentService(25076): Acquiring wakelock 10-08 11:56:16.082: V/GCMBaseIntentService(25076): Intent service name: GCMIntentService-GCMIntentService-1 10-08 11:56:16.092: D/GCMIntentService(25076): onMessage - context: android.app.Application@41dce920 10-08 11:56:16.092: V/PushPlugin(25076): sendExtras: caching extras to send at a later time. 10-08 11:56:16.092: D/GCMIntentService(25076): onMessage - foreground: true 10-08 11:56:16.092: D/GCMIntentService(25076): onMessage - message: ? Peace,Love ? and PhoneGap ?! 10-08 11:56:16.092: V/GCMBaseIntentService(25076): Releasing wakelock

cutzenfriend commented 10 years ago

Okay it would be nice if someone could notify us here if we can rebuild on build and submit to store :) :+1:

jpescada commented 10 years ago

Just tested @scotthooker's #100 patch, but it still doesn't work when the app is closed. Via logcat I can see the notification coming in but the app doesn't pick the intent. I'll try @rihdus' patch now.

scotthooker commented 10 years ago

@jpescada - yeh that patch doesn't work so I cancelled the pull request.

If @rihdus patch doesn't work could you test my latest pull request? https://github.com/phonegap-build/PushPlugin/pull/102

jpescada commented 10 years ago

@scotthooker unfortunately #85 didn't work nor @rihdus' fix. still can't get notifications when the app is closed.

scotthooker commented 10 years ago

@jpescada Try #102 :)

I've also added you on twitter if you want to chat. Looks like we are pretty close to each other in London btw

jpescada commented 10 years ago

Ok. School boy error. I was applying the fix on the wrong file.

The .java files for this PushPlugin are being installed in 3 different folders:

  1. ProjectName/cordova/plugins/com.phonegap.plugins.PushPlugin/src/android/com/plugin/gcm
  2. ProjectName/platforms/android/cordova/plugins/com.phonegap.plugins.PushPlugin/src/android/com/plugin/gcm
  3. ProjectName/platforms/android/src/com/plugin/gcm

And I only edited in the first two earlier today. Instead of editing in the third and correct one. Doh!

So yes, @rihdus' fix is actually working.

Submitted pull request #103 with credits to @rihdus and @scotthooker.

scotthooker commented 10 years ago

@bobeast thanks for committing that in I can confirm all is working as expected so we are now not under pressure to fix the issue properly.

I think @jpescada is probably the better fix code wise but needs testing fully in all the scenarios - app open, app minimised, app resumed, app closed, app forced close etc... so that we don't get the same problems as before with all states not being tested.

cutzenfriend commented 10 years ago

Is this now properly fixed on build!?

scotthooker commented 10 years ago

@domenikniemietz its fixed on build and works for me.

@bobeast how do you test on build before you release a patch - for future reference? If I make a patch for anything hows best to test it.

bobeast commented 10 years ago

@scotthooker - A plugin change should be tested first with a local build. Once tested, it is submitted through the plugin portal at https://build.phonegap.com/plugins.

From that point it goes through an approval process similar to Apple's App store. Once approved it shows up live.

There is currently no mechanism available to allow 3rd party submitters to "pre-test" in the Build environment. If it builds locally, and is submitted, really important feeling people will validate and do a cursory test against a staging server prior to approval.

We are looking into the possibility of exposing a test server to 3rd parties, but its frankly a bit low on our priority list, because we like feeling really important ;)

denboogert commented 10 years ago

Hi all, unfortunately I did not find it to work with PhoneGap Build 3.0.0 and 3.1.0 and default (unspecified) version of PushPlugin.

To test it, I removed the app and reinstalled it on Samsung S3 via de PhoneGap Build link. Then I used a local server to send (identical test) notifications under different circumstances (with a "message", "title" and "msgcnt", and timeToLive 3000). The sending is successful.

Case app active in foreground: notification is displayed in the app (not in status bar)

Case app minimized: notification in status bar, when app is opened notification is displayed twice.

Case app closed (or not started): no notification in status bar, when app is opened one (a maximum of one) notification is displayed.

I would be happy to do some further testing. If you think there may be another reason why this is not working, that information would also be welcome.

cherouvim commented 10 years ago

Any news on this one?

phonegap build 3.3, notification only received when app is in foreground

kelvcutler commented 10 years ago

Check out my answer here: https://github.com/phonegap-build/PushPlugin/issues/168#issuecomment-36225892

If you don't include explicit payload values for 'title' AND 'message' you won't get the notification made when the app is in the background.

cutzenfriend commented 10 years ago

The are included and it worked with phonegap < 3.3 before

Am 05.03.2014 um 18:17 schrieb kelvcutler notifications@github.com:

Check out my answer here: #168 (comment)

If you don't include explicit payload values for 'title' AND 'message' you won't get the notification made when the app is in the background.

— Reply to this email directly or view it on GitHub.

cherouvim commented 10 years ago

Worked! Thanks!

kelvcutler commented 10 years ago

@domenikniemietz,

Yes, sorry. I realize there seems to be other issues at hand beyond the problem and solution I mentioned. However, it was a very useful discovery and happened to be the only thing I was missing with my app. This issue here was the first issue I started tracking in hopes of finding a solution so I thought it'd be useful (which appears to have been for @cherouvim already) to include here.

Good luck!

sandeepshetty commented 10 years ago

Related to #35

nvcken commented 9 years ago

@cherouvim I implement push notification on android work fine in this case: App open - inline ( foreground) App close / home screen press. (background) But it not work in case after lock screen a few minutes

celle886 commented 9 years ago

@nvcken I have the same problem. I tested on PhonegapBuild and local Build and with older Versions. Do you get it working?

nvcken commented 9 years ago

@colene @EddyVerbruggen @davejohnson @shazron @purplecabbage @wildabeast if set delay_while_idle then push notification work fine when phone idle / screen lock. But it app be forced close or phone restart , push notification not work , have you solved it ?

celle886 commented 9 years ago

@nvcken I had delay_while_idle set to true and the push notifications will also not appear when the app is in background and the lock screen is active.

I have to finish other parts of my app and then i will take the time to fix this, maybe has somebody then a other approach.

nvcken commented 9 years ago

@celle886 delay_while_idle should set false then push notification will work when the app is in background and the lock screen is active

celle886 commented 9 years ago

@nvcken you are right. Now it's working. In the first test's it also works when the app is not running. I will make some more tests. Write again later.

denboogert commented 9 years ago

Dit e-mailadres is niet meer actief.

Email voor dit adres belandt in een e-mailbox voor inactieve e-mailadressen. Email in deze box wordt slechts af en toe bekeken. Over enkele maanden zal het e-mailadres helemaal niet meer werken. Als maatregel tegen spam, wijzigen wij periodiek onze e-mailadressen.

celle886 commented 9 years ago

@nvcken it's working. When smartphone is rebooted or the app is closed with application manager, it's working too. And also after a few minutes lock screen.

How can i help you to fix your code?

nvcken commented 9 years ago

@celle886 You mean when phone restart or app force closed, push notification work too Please help me fix that? Could you please send me your sample work code to nvcken@gmail.com

nvcken commented 9 years ago

@celle886 ping for help

celle886 commented 9 years ago

@nvcken sorry, that you have to wait, but i have a deadline today and when i finished my work, i write you an email.

nvcken commented 9 years ago

@celle886 Ok, thanks

zolakt commented 9 years ago

Any news on this issue? I'm still having a problem when the app is closed.

It works when the app is in foreground, background, when the phone is in sleep mode. But when you manually close the app from the task list, push notifications no longer arrive.

I'm using Phonegap build 3.5 and PushPlugin 2.4.0

nvcken commented 9 years ago

@zolakt delay_while_idle should set false then push notification will work when the app is in background and the lock screen is active

zolakt commented 9 years ago

@nvcken Ok... where should delay_while_idle be set? I can't find it in code. I'm using PGB so I can't modify java files

RMarietta commented 9 years ago

I'm encountering the same issue:

  1. Using PGB to build the app (3.6.3) with PushPlugin (2.4.0)
  2. Android device does not display notification after force quit (app is not running in background)

I've read through all the comments here... I tried using a title and message in the push notification and have delay_while_idle set to false and the notification still does not get displayed.

Was anyone able to get this to work?

marie-dk commented 9 years ago

@RMarietta Cordova 4.2 with plugin 2.4 on Android 4.4.2 ... Same thing here... receiving nothing when the app is closed. I tried delay_while_idle with both true and false... it had no effect. As @nvcken said, it is not clear where to set this value. I found a php gcm script to send messages where this value can be set: http://www.go4expert.com/articles/send-android-push-notifications-using-t29896/ (in the $fields array). But I have no idea where to set this value when using pubnub javascript or php script.

But either way, setting delay_while_idle and a message title, had no effect.

celwell commented 9 years ago

Make sure you are sending a JSON payload with the correct format. Sending a raw default message will only work when app is in foreground.

{ "GCM":"{ "data":{ "message":"Check out these awesome deals!" } }" }

shprink commented 8 years ago

@celwell I followed your format and it is the same only works with foreground.

{
    "event": "message",
    "from": "219209889674",
    "collapse_key": "push",
    "foreground": true,
    "payload": {
        "GMC": {
            "data": {
                "id": 0,
                "message": "This is a test notification"
            }
        }
    }
}
shprink commented 8 years ago

Made it work like this:

{
    "event": "message",
    "from": "219209889674",
    "collapse_key": "push",
    "foreground": true,
    "payload": {
        "message": "This is a test notification"
    }
}
celwell commented 8 years ago

You wrote "GMC" instead of "GCM".

shprink commented 8 years ago

@celwell Yeah good catch, nevermind, I found that the message key is Mandatory, if it not present than no push notifications others than foreground.

ghost commented 8 years ago

Hi,

My project has the same issue as reported in this topic. We receive the notifications when:

But the notifications are never received if the application is completely closed (slide up the app in the list of opened apps, or restart phone).

I tried to always display notifications/call callback function in the root of GCMIntentService.onMessage to check whether the problem is in this function. But onMessage is never called when the application is completely closed. It seems to be the cause, since it contains the code to trigger the notification.

Recent suggestions does not seem to apply or help:

{
    collapse_key : "do_not_collapse",
    event : "message",
    foreground : true,
    from : "123456789012",
    message : "Some notification text",
    msgcnt : "8",
    payload : {
        message : "Some notification text",
        msgcnt : "8",
        title : "My notification"
    }
}

Any idea about how to fix it?

Since I am not the only one with this issue, I guess it should be reopened.

Thanks!

ghost commented 8 years ago

I answer my own question after some investigation, in case someone has the same issue.

My issue was because I have a Xiaomi phone with MIUI as OS. It embeds a feature to forbid apps to run in background if not allowed in a whitelist (Detailed explanation).

Solution: allow the app to auto-start in Security Center app > Permissions > Autostart > switch on your app

I was confused because apps like Wechat (chinese Whatsapp) and Google were already working. Wechat was already allowed, and Google... maybe because it is sync (settings/accounts...).

Android 4.4.1 and 4.4.2 had an issue with the same behavior, but it seems to be fixed in 4.4.4.

abhinavgujjar commented 8 years ago

@aorylamballe Thanks so much for posting this information. I just checked on an Nexus phone and the notifications come in even when the app is closed

apolkingg8 commented 8 years ago

@aorylamballe You save my days! :beer:

mfkenson commented 8 years ago

@aorylamballe You save my days! +1 mine is asus zenfone2 with auto-startup manager (this stupid security app also disable notifications from my app by default..)

PaulCannell commented 8 years ago

So Ive used this plugin before about a year ago. Then today I create a new ionic project and I get my notification in code on the device but I dont get a notification in the android header bar (where the whatsapp icon shows when you have new / unread messages) Im also not getting any messages if the app is in the background. Cordova version 6.0.0 com.phonegap.plugins.PushPlugin 2.5.0

Any ideas?

macdonst commented 8 years ago

@PaulCannell switch to https://github.com/phonegap/phonegap-plugin-push. I'm maintaining that one and the Ionic guys are helping out as well.

PaulCannell commented 8 years ago

Legend. So much easier. Up and running already Tx