katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.56k stars 1.74k forks source link

Android Build for Android Platfom 10.1.2 or 11.0.0 Crashes the app. #1987

Open bevinGithub opened 1 year ago

bevinGithub commented 1 year ago

I have created a new ionic Cordova angular app trying to test the Android 11 upgrade. The local notifications plugin is working if l add platform 10.0.0 which Target API Level 30 which you are not able to publish a new app on Google Playstore anymore.

I have the following environment setup. Ionic:

Ionic CLI : 6.20.1 (C:\Users\Tigere Bervin\AppData\Roaming\npm\node_modules\@ionic\cli) Ionic Framework : @ionic/angular 6.2.8 @angular-devkit/build-angular : 14.2.3 @angular-devkit/schematics : 14.2.3 @angular/cli : 14.2.3 @ionic/angular-toolkit : 6.1.0

Cordova:

Cordova CLI : 11.0.0 Cordova Platforms : android 10.1.2 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 7 other plugins)

Utility:

cordova-res : 0.15.4 native-run : 1.7.1

System:

NodeJS : v14.15.4 (C:\Program Files\nodejs\node.exe) npm : 6.14.10 OS : Windows 10

C:\ionicAndroid12\prosperclocknew>cordova plugin list cordova-plugin-androidx-adapter 1.1.3 "cordova-plugin-androidx-adapter" cordova-plugin-androidx 3.0.0 "cordova-plugin-androidx" cordova-plugin-badge 0.8.8 "Badge" cordova-plugin-device 2.0.2 "Device" cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 5.0.0 "cordova-plugin-ionic-webview" cordova-plugin-local-notification 0.9.0-beta.2 "LocalNotification" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.2 "StatusBar"

Local Notifications crashes the app, l have troubleshoot the issue and the problem is on the trigger any configurations the app is crashing. The settings below works on platform 10.0.0 works very well but we cannot publish with Platform Level 10.0.0

  this.localNotifications.schedule({
    id: 1,
    text: 'Single LocalNotification',
    trigger: {every: { weekday: 1, hour: 11, minute: 31 }, count: 1}
  });

  this.localNotifications.schedule({
    id: 1,
    text: 'Single LocalNotification',
    trigger: {at: new Date(new Date().getTime() + 3600)},
  });

What do l need to do to make the upgrade work with the Local Notifications plugin.

jeanteke commented 1 year ago

THIS IS THE SOLUTION: https://github.com/katzer/cordova-plugin-local-notifications/issues/1983

bevinGithub commented 1 year ago

THIS IS THE SOLUTION: #1983

Thanks for the response, so the ionic cordova plugin add cordova-plugin-local-notification-12 is just not available on the github. I noticed tht there is a command that you need to specify the version number, whats not clear is that if there was ever a new version for support of Android 12 or Api 32. I will try that way and see if it works , thank you very much

lyudmil commented 1 year ago

THIS IS THE SOLUTION: #1983

I don't fully agree. The fork of the plugin you propose is a little suspicious.

To start, it's clearly a fork of this repository, except it was created by copying the files into a new repository. It therefore has erased all of the commit history of the current plugin. This doesn't allow us to easily inspect what changed and is also just strange.

If one does make the effort to inspect the changes, some of them seem unnecessary and seem to decrease the quality of the code for no benefit. Allow me to draw your attention to https://github.com/bhandaribhumin/cordova-plugin-local-notification-12/commit/e79584161eb555e18a0178e4fdcda43ddbd902d6 and https://github.com/bhandaribhumin/cordova-plugin-local-notification-12/commit/582e588f0651745cada6e9249658f0bc513233c0 and the comments I've left there.

The rest of the commits are changes to the docs to add the author as a contributor, except for this commit, which isn't authored by the repo owner: https://github.com/bhandaribhumin/cordova-plugin-local-notification-12/commit/a89c603f716f119db1b5a6e5add92f3b419bde46. There's also https://github.com/bhandaribhumin/cordova-plugin-local-notification-12/commit/f98891931fdda3b94781e81b1b5c8200d46d1e74, which looks like it could be valuable. I suspect these are the commits that actually fix the crash. I'll work on confirming this on my own fork and I'll post back.

I wouldn't recommend adding a dependency to this fork to your project. Until the issues I've pointed out have been resolved, I don't see evidence that the author will nurture the code well going forward.

bevinGithub commented 1 year ago

THIS IS THE SOLUTION: #1983

I don't fully agree. The fork of the plugin you propose is a little suspicious.

To start, it's clearly a fork of this repository, except it was created by copying the files into a new repository. It therefore has erased all of the commit history of the current plugin. This doesn't allow us to easily inspect what changed and is also just strange.

If one does make the effort to inspect the changes, some of them seem unnecessary and seem to decrease the quality of the code for no benefit. Allow me to draw your attention to bhandaribhumin/cordova-plugin-local-notification-12@e795841 and bhandaribhumin/cordova-plugin-local-notification-12@582e588 and the comments I've left there.

The rest of the commits are changes to the docs to add the author as a contributor, except for this commit, which isn't authored by the repo owner: bhandaribhumin/cordova-plugin-local-notification-12@a89c603. There's also bhandaribhumin/cordova-plugin-local-notification-12@f988919, which looks like it could be valuable. I suspect these are the commits that actually fix the crash. I'll work on confirming this on my own fork and I'll post back.

I wouldn't recommend adding a dependency to this fork to your project. Until the issues I've pointed out have been resolved, I don't see evidence that the author will nurture the code well going forward.

Thanks for the info so in the mean time l l have to look for other avenues for Alarms setting.

lyudmil commented 1 year ago

In general, I'd recommend this fork of the local notifications plugin, since it's more actively maintained: https://github.com/timkellypa/cordova-plugin-local-notifications

That fork still crashes on API level 31, so merely using it doesn't solve things. This PR fixes things for the app we've tested, so it's worth keeping an eye on: https://github.com/timkellypa/cordova-plugin-local-notifications/pull/8

Unfortunately, there's no word on when it might be merged in. If you need a fix today you could use the fork that made the PR in the first place: https://github.com/fquirin/cordova-plugin-local-notifications

Hope this helps.

bevinGithub commented 1 year ago

In general, I'd recommend this fork of the local notifications plugin, since it's more actively maintained: https://github.com/timkellypa/cordova-plugin-local-notifications

That fork still crashes on API level 31, so merely using it doesn't solve things. This PR fixes things for the app we've tested, so it's worth keeping an eye on: timkellypa#8

Unfortunately, there's no word on when it might be merged in. If you need a fix today you could use the fork that made the PR in the first place: https://github.com/fquirin/cordova-plugin-local-notifications

Hope this helps.

I have tested the plugin katzer / cordova-plugin-local-notifications it doesnt work on the events onTrigger

onDeviceReady() { this.localNotifications.on('trigger').subscribe((test: any) => { console.log('Trigger' + JSON.stringify(test)); }); }

Its not logging the subscription out as l need to process data from the data: { test: 'Test Data }.

I will try the one you recommended

bevinGithub commented 1 year ago

THIS IS THE SOLUTION: #1983

Hi the local Notifications 12 does trigger notifications but the events onClick or Trigger do not work and l need the trigger to process my notification next step any ideas.

bevinGithub commented 1 year ago

Anyone has got a working solution on getting events on local notifications on this Android 12 local notification

Topiya commented 1 year ago

Anyone has got a working solution on getting events on local notifications on this Android 12 local notification

I have solved this as below.

I have uninstalled "cordova-plugin-local-notification": "^0.9.0-beta.2" and added "cordova-plugin-local-notification-12": "0.1.3". Also uninstalled "cordova-plugin-badge" since "cordova-plugin-local-notification-12" will automatically install "cordova-plugin-badge-fix": "^0.8.10".

Deleted Platforms and Plugin folder before starting a new build process.

bevinGithub commented 1 year ago

Hi Topiyo I did install the Corodva-plugin-local-notification-12 it does play the notification but the events are not triggering. I need the trigger event to play custom files. Please confirm if you able to capture trigger events and log them successfully.

Topiya commented 1 year ago

I am using it as below. Which is giving Local Notification at specified time in 'trigger' attribute.

        this.localNotifications.schedule({
          id: id,
          title: notificationType,
          text: Ename,
          trigger: { at: new Date(new Date().setHours(timeArray[0], timeArray[1], timeArray[2])) },
          sound: null
        });
bevinGithub commented 1 year ago

Hi Topiya, that code works to have a local notification. What l want is the next step when you get the notification. This is done in Events triggers, the code below runs after the notifications triggers that's the part l want which is not functional. I can confirm that the event below is not triggering please confirm if it works your side.

I have android-12 local notification plugin installed

onDeviceReady() { this.localNotifications.on('trigger').subscribe((test: any) => { console.log('Trigger' + JSON.stringify(test)); }); }

Topiya commented 1 year ago

No. Above trigger event code doesn't work for me.

bevinGithub commented 1 year ago

That's the part l need to play custom audios when the notification triggers then the event plays the audios that a user sets

lyudmil commented 1 year ago

@bevinGithub, you seem to be talking about a different issue. This discussion is about the app crashing on more recent Android platforms.

The most actively maintained fork I know of is this: https://github.com/timkellypa/cordova-plugin-local-notifications. Maybe open an issue there or find out whether anyone else is reporting the same problem?

That said, even the fork above isn't super-active, since in this discussion I'm recommending a different fork that includes the fix for the crash. The upshot is that this plugin seems to be looking for active maintainers. Until it finds some, I think we're stuck trying to do what we can to resolve the specific bugs we're running into.

alitalaee commented 10 months ago

Hi Topiya , I did install the Corodva-plugin-local-notification-12 with the below command npm i cordova-plugin-local-notification-12 cordova plugin add cordova-plugin-local-notification-12

from This Github link

but i cant use it, because i cant import it at all

cordova.plugins.notification.local.schedule

throw the error of Property 'notification' does not exist on type 'CordovaPlugins'.ts(2339)

import {LocalNotifications} from 'cordova-plugin-local-notification-12'

throw the error of Cannot find module 'cordova-plugin-local-notification-12' or its corresponding type declarations.ts(2307)

installed version

"cordova-plugin-local-notification-12": "^0.1.3" can you help me please

https://github.com/bhandaribhumin/cordova-plugin-local-notification-12/issues/11