Cordova-plugin-local-notifications: Local Notifications not trigered when app closed from background

Created on 25 Feb 2016  Â·  20Comments  Â·  Source: katzer/cordova-plugin-local-notifications

Hi team,

Really thank you for the wonderful plugin.Everything works fine until the app is running in the background, However the issue arises when i close the app from background, It doesnot trigger any of the alert or notification.Below is the detailed scenario.

Issue : Registered a notification to trigger after 5 sec.
Just cleared the app from background.
notification or alert not received.
Mobile : Lenovo A6000 Plus.

thank you in advance for any suggestions or workaround

bug android

Most helpful comment

Me To, +1

All 20 comments

Me To, +1

did you swipe app on recent apps?, i "fix it" making app non visible on recent app, to prevent closed it in background https://github.com/katzer/cordova-plugin-local-notifications/issues/786

yeah @dansanti I swiped the app from recent apps.
As per your suggestion, I have added the paramerter android:excludeFromRecents="true" to the Main Activity. This trick works well but as per the performance its not the elegant solution.

Now my suggestion is to put the parameter to the plugin activity. but when i do that i'm getting Manifest merger error when building the app.

Hi

I am facing the same problem notifications are not shown once the user remove all apps using the "kill/close all app" function on Android phones. Setting the android:excludeFromRecents="true" will only hide the app from the task list, but the kill all will still close the "hidden" app.

When I re-open the app and display the .getScheduled returns me all the notifications that were scheduled.

Is it suppose to behave that way? Thanks.

I too have similar problem. is it something to do with device ? I am seeing this in my Xiomi. In push-plugin they referred this as a Quirk.
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#huawei-and-xiaomi-phones

Hi Natanraj

I have similar issues on Samsung phone not only Xiaomi. Some of the daily local notifications continue to work fine. This is even after I restarted the Samsung phone.

However some especially the hourly notifications are not showing.

Is this still an issue?

Hi

I have recreated a test and running it. Will let you know the results end
of my day.

Thanks

On 20 Feb 2017 18:55, "Rob Willett" notifications@github.com wrote:

Is this still an issue?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/katzer/cordova-plugin-local-notifications/issues/886#issuecomment-281048779,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQko8ES6BezUo27q0UY8P7JGgUUGxqC-ks5reXE8gaJpZM4Hie-8
.

Hi Rob

I ran the test app overnight. I left the test app running in the background

  • i.e. it is one of the app in the list.

Checked in the morning and confirmed there were 4 notifications on my phone

  • 1 each at the hour (6:00), quarter past (5:15), half past (5:30) and
    quarter to (5:45).

I then stop all app using the device/Android stop all button. The
notifications stopped from then onwards. Open the test app and checked the
scheduled notifications (cordova.plugins.notification.local.getScheduled) -
and the 4 notifications are still "scheduled" and returned by the call but
no notifications are received.

// on device ready
function notificationEventsHandler() {

cordova.plugins.notification.local.on("click", function (notification) {

});

}

// called below to schedule 4 hourly notifications: on the hour, quarter
past, half past and quarter to
function newNotification() {

var nexthr = new Date();
nexthr.setHours(nexthr.getHours()+1);   // set to an hour later

// set to the notification time - on the hour, quarter past, half past

and quarter to

var d = new Date(nexthr.getYear() + 1900, nexthr.getMonth(),

nexthr.getDate(), nexthr.getHours(), 0, 0, 0);

cordova.plugins.notification.local.schedule({
        id: 1,
        title: "On the hour. Every hour.",
        text: "Test",
        at: d,
        every: "hour",
        led: "0000FF"
    }, function () {
});

d.setMinutes(15);
cordova.plugins.notification.local.schedule({
        id: 2,
        title: "Every quarter past.",
        text: "Test",
        at: d,
        every: "hour",
        led: "0000FF"
    }, function () {
});

d.setMinutes(30);
cordova.plugins.notification.local.schedule({
        id: 3,
        title: "Every half hour.",
        text: "Test",
        at: d,
        every: "hour",
        led: "0000FF"
    }, function () {
});

d.setMinutes(45);
cordova.plugins.notification.local.schedule({
        id: 4,
        title: "Every quarter to.",
        text: "Test",
        at: d,
        every: "hour",
        led: "0000FF"
    }, function () {
});

}

On Tue, Feb 21, 2017 at 6:15 AM, sengmow sengmow@gmail.com wrote:

Hi

I have recreated a test and running it. Will let you know the results end
of my day.

Thanks

On 20 Feb 2017 18:55, "Rob Willett" notifications@github.com wrote:

Is this still an issue?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/katzer/cordova-plugin-local-notifications/issues/886#issuecomment-281048779,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQko8ES6BezUo27q0UY8P7JGgUUGxqC-ks5reXE8gaJpZM4Hie-8
.

I know that we test explicitly for local notifications being sent when the app is terminated in our app and it works OK on a Nexus 5 running Android 5 and 6.

We don't use every: though. Try it without and see what happens.

I think you want me to test scheduling a future notification say an hour
later and close/exit the app - I will let you know. How do I create repeat
notifications if I don't use "every"?

BTW, tested the app on Samsung S5 running Android 6. Similar issue, the
notifications stopped.

On Tue, Feb 21, 2017 at 3:03 PM, Rob Willett notifications@github.com
wrote:

I know that we test explicitly for local notifications being sent when the
app is terminated in our app and it works OK on a Nexus 5 running Android 5
and 6.

We don't use every: though. Try it without and see what happens.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/katzer/cordova-plugin-local-notifications/issues/886#issuecomment-281261712,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQko8MdzE6ITmXPWTIElfacmUVuB0AHfks5reoxNgaJpZM4Hie-8
.

Yes schedule in the future and see what happens.

If that works, then add in the every: element to see if its a bug.

Hi

Removed the "every" - results as follow

  1. Notifications received as scheduled with test app running

  2. If exited notifications stopped.

2a. No notifications after scheduling and app immediately exited

2b. Scheduled 4 notifications. Exit the app. After the time lapsed for 3
notifications scheduled (no notications received) I checked the scheduled
notifications and only the last remained.
Started the test app but still no notification. Checked the notification
schedule and was empty.

On 21 Feb 2017 15:47, "Rob Willett" notifications@github.com wrote:

Yes schedule in the future and see what happens.

If that works, then add in the every: element to see if its a bug.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/katzer/cordova-plugin-local-notifications/issues/886#issuecomment-281268736,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQko8FYdomYdS8iHGFNl__spzcm4kyoAks5repafgaJpZM4Hie-8
.

Hi

I ran the test app (without "every") on Samsung S5. Scheduled the
notifications an hour later. Exit all app. I receive the notifications
pretty much on time.

In summary:
On Mi4, with or without the every, after the app is exited, notifications
not received.

On Samsung S5, with "every" notifications stopped after the app exited.
Seems to be fine if scheduled without "every".

On Tue, Feb 21, 2017 at 10:59 PM, sengmow sengmow@gmail.com wrote:

Hi

Removed the "every" - results as follow

  1. Notifications received as scheduled with test app running

  2. If exited notifications stopped.

2a. No notifications after scheduling and app immediately exited

2b. Scheduled 4 notifications. Exit the app. After the time lapsed for 3
notifications scheduled (no notications received) I checked the scheduled
notifications and only the last remained.
Started the test app but still no notification. Checked the notification
schedule and was empty.

On 21 Feb 2017 15:47, "Rob Willett" notifications@github.com wrote:

Yes schedule in the future and see what happens.

If that works, then add in the every: element to see if its a bug.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/katzer/cordova-plugin-local-notifications/issues/886#issuecomment-281268736,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQko8FYdomYdS8iHGFNl__spzcm4kyoAks5repafgaJpZM4Hie-8
.

This seems to be a bug with the Mi4 at least.

It works on our Nexus 5 on Android 5 and 6 BUT we don't use every.

I'll flag this as a bug. I don't maintain the code so can't say anything about it being fixed.

BTW, I am unable to cancel notification
with cordova.plugins.notification.local.cancel. What is "scope"?

cordova.plugins.notification.local.cancel(1, function () {
// Notification was cancelled
}, scope);

On Wed, Feb 22, 2017 at 5:10 PM, Rob Willett notifications@github.com
wrote:

This seems to be a bug with the Mi4 at least.

It works on our Nexus 5 on Android 5 and 6 BUT we don't use every.

I'll flag this as a bug. I don't maintain the code so can't say anything
about it being fixed.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/katzer/cordova-plugin-local-notifications/issues/886#issuecomment-281611325,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQko8GxXFptW0a18faereTo_0nnD7zOyks5re_uIgaJpZM4Hie-8
.

The scope is your context where the callback will be called. That will be
the 'this' inside your callback function.
Of course that parameter is optional. If you don't define, then the this
will be the function scope.

2017-02-22 14:57 GMT+01:00 sengmow notifications@github.com:

BTW, I am unable to cancel notification
with cordova.plugins.notification.local.cancel. What is "scope"?

cordova.plugins.notification.local.cancel(1, function () {
// Notification was cancelled
}, scope);

On Wed, Feb 22, 2017 at 5:10 PM, Rob Willett notifications@github.com
wrote:

This seems to be a bug with the Mi4 at least.

It works on our Nexus 5 on Android 5 and 6 BUT we don't use every.

I'll flag this as a bug. I don't maintain the code so can't say anything
about it being fixed.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
notifications/issues/886#issuecomment-281611325>,
or mute the thread
auth/AQko8GxXFptW0a18faereTo_0nnD7zOyks5re_uIgaJpZM4Hie-8>
.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/katzer/cordova-plugin-local-notifications/issues/886#issuecomment-281675981,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACQrUC-2if5moNJg35pmtz0DGxKwUNAFks5rfD7UgaJpZM4Hie-8
.

Please upgrade to v0.9-beta. The notifications do trigger, however there's no trigger callback to invoke if the app isn't running (in foreground).

Thanks, I will give it a go.

On Tue, Nov 7, 2017 at 7:42 PM, Sebastián Katzer notifications@github.com
wrote:

Please upgrade to v0.9-beta. The notifications do trigger, however there's
no trigger callback to invoke if the app isn't running (in foreground).

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/katzer/cordova-plugin-local-notifications/issues/886#issuecomment-342457827,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQko8CKQAcAXwt5rHOxqwx-34pXi4PI6ks5s0EI8gaJpZM4Hie-8
.

--
Chants Keeper for Android
https://play.google.com/store/apps/details?id=sa.chants.keeper

@sengmow I have a Xiaomi Redmi Note 4x and a Xiaomi Redmi 3 Pro, finally I found the problem: When you install your application, the autostar permission is disabled by default, so if the application is closed you can not receive notifications.

In MIUI 8 and 9 go to settings > app settings > permissions > autostart, here you can allow your application to autostart.

I hope you find it useful.

Was this page helpful?
0 / 5 - 0 ratings