katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.76k forks source link

Android getTriggeredIDs = null #744

Closed chrisvanderkooi closed 8 years ago

chrisvanderkooi commented 8 years ago

I am having an issue on any version of Android I have tested (5.0.2 & 4.2.1) that I cannot see what notifications have been fired. When I do getTriggeredIds(), it returns null even though I've scheduled some notifications and they've been fired. Also, even though the notifications have been triggered, they are still showing in getScheduledIds() and not getTriggeredIds().

On iOS when I test this, everything works fine. Once a notification is triggered, it is removed from scheduled and is moved into triggered.

On Android 4.2.1, getTriggeredIds() returns null, however on iOS it works and I get an empty array. On Android 5.0.2, getTriggeredIds() returns an empty string "".

I am using a code snippet like this:

cordova.plugins.notification.local.getTriggeredIds(function (notifications) {
    console.log('Triggered IDs');
    console.log(notifications);
    // returns null, should return []
})

I can't seem to get a list of what notifications have fired and whats still scheduled on Android.

Edit: I've tried the Kitchen Sink Demo app on Android as well. Scheduled notifications that are fired are not shown as triggered either.

Tawpie commented 8 years ago

@cmgchris. I got getScheduled to work by saving notifications to a global variable (yea yea, I know—it wasn’t how I wanted to do it either) declared outside of the getTriggered method call. Inside the getTriggered function, I assigned notifications to the global and getScheduled was just fine. WARNING: I haven't tested getTriggered on either Android or iOS... so I may be wrong. But it does work for getScheduled!

/* ---------------- Katzer local notifications -------------- */ var gaAllScheduledLocalNotifications = []; function testGetScheduledLNs() { if (isLocalNotificationPluginValid()) { cordova.plugins.notification.local.getScheduled(function (notifications) { gaAllScheduledLocalNotifications = notifications; }); } else { console.log("TS.tGSLN - unknown result, plugin is invalid or disallowed"); } }

function testGetScheduledLNCount() { if (isLocalNotificationPluginValid()) { testGetScheduledLNs(); } else { console.log("TS.tGSLNC - unknown result, plugin is invalid or disallowed"); } var iReturnMe = 0; if (isDefined(gaAllScheduledLocalNotifications) && isDefined(gaAllScheduledLocalNotifications.length)) { iReturnMe = gaAllScheduledLocalNotifications.length; } return iReturnMe; }

var gaAllTriggeredLocalNotifications = []; function testGetTriggeredLNs() { if (isLocalNotificationPluginValid()) { cordova.plugins.notification.local.getTriggered(function (notifications) { gaAllTriggeredLocalNotifications = notifications; }); } else { console.log("TS.tGTLN - unknown result, plugin is invalid or disallowed"); } }

function testGetTriggeredLNCount() { if (isLocalNotificationPluginValid()) { testGetTriggeredLNs(); } else { console.log("TS.tGTLNC - unknown result, plugin is invalid or disallowed"); } var iReturnMe = 0; if (isDefined(gaAllTriggeredLocalNotifications) && isDefined(gaAllTriggeredLocalNotifications.length)) { iReturnMe = gaAllTriggeredLocalNotifications.length; } return iReturnMe; }

On Nov 5, 2015, at 2:05 PM, Christopher VanderKooi notifications@github.com wrote:

I am having an issue on any version of Android I have tested (5.0.2 & 4.2.1) that I cannot see what notifications have been triggered. When I do getTriggeredIds(), it returns null even though I've scheduled some notifications and they've been triggered. Also, even though the notifications have been triggered, they are still showing in getScheduledIds().

On iOS when I test this, everything works fine. Once a notification is triggered, it is removed from scheduled and is moved into triggered.

On Android 4.2.1, getTriggeredIds() returns null, however on iOS it works and I get an empty array. On Android 5.0.2, getTriggeredIds() returns an empty string "".

I am using a code snippet like this:

cordova.plugins.notification.local.getTriggeredIds(function (notifications ) {

console.log('Triggered IDs' );

console.log (notifications);

// returns null, should return []

    })

I can't seem to get a list of what notifications have fired and whats still scheduled on Android.

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

chrisvanderkooi commented 8 years ago

Hi @Tawpie Thanks for the reply. I tried what you proposed but as I had thought, I am still getting null when calling getTriggeredIds() even though some scheduled notifications had already fired. Also, the scheduled notifications have not moved from getScheduledIds().

My code:

var triggered_notifications = [];

$scope.getTriggeredNotifications = function() {
    cordova.plugins.notification.local.getTriggeredIds(function (triggered) {
        triggered_notifications = triggered;
    });

    console.log(triggered_notifications);
};
Tawpie commented 8 years ago

@cmgchris not being removed from scheduled once they've fired seems like an actual bug.

One other thing is that if you getTriggered(id#) with a specific integer id, the plugin returns a promise so you have to use a .then property on the method call. Getting all scheduled doesn't use promises I don't think--at least adding a .then doesn't work. Maybe get all triggered uses promises?

chrisvanderkooi commented 8 years ago

@Tawpie getTriggeredIds() doesn't use promises. Thanks though! Only thing I can think of that I am unable to test, is that I am missing cordova-plugin-android-support-v4 plugin, however when I add that, I am unable to build and get an error which I can't seem to fix:

:dexDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dexDebug'.
Tawpie commented 8 years ago

@cmgchris there are several threads on that one and there were conflicts with the pushplugin but in the last week or so they seem to have been fixed. I would suggest removing the android platform, then remove all the plugins, then reinstall all the plugins and finally add the android platform in again. I've been successful with the following plugin 'load':

third party cordova plugins add cc.fovea.plugins.inapppurchase@3.4.1 cordova plugins add com.smartmobilesoftware.inappbilling@3.0.0 cordova plugins add de.appplant.cordova.plugin.email-composer cordova plugin add https://github.com/leecrossley/cordova-plugin-background-task.git cordova plugin add https://github.com/apache/cordova-plugin-whitelist.git

as of 10/27, Katzer seems to have updated his plugin so the following works for both android and iOS cordova plugins add https://github.com/phonegap-build/PushPlugin.git cordova plugins add https://github.com/katzer/cordova-plugin-local-notifications.git