katzer / cordova-plugin-local-notifications

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

App crash android oreo #1786

Closed luca-itro closed 5 years ago

luca-itro commented 5 years ago

First of all thank you for this plugin. As you wrote on readme it have problems with android Oreo...

The app crash with the sample code: cordova.plugins.notification.local.schedule({ title: 'My first notification', text: 'Thats pretty easy...', foreground: true });

Your Environment

Steps to Reproduce

simply use the code above onDeviceReady

Debug logs

logcat.txt

Tawpie commented 5 years ago

make sure your plugin version is beta.3 or later

luca-itro commented 5 years ago

beta .3 is working with AVD 8.1 but not with physical device 8.1: still having the same issue. Debugging with android studio i found that the resId is loaded in getSmallIcon https://github.com/katzer/cordova-plugin-local-notifications/blob/06baff7674014d525238ae2b86f20ebf1622dda5/src/android/notification/Options.java#L379 It goes in the first if statement trying to load the DEFAULT_ICON (that is unavailable) so it get the system resource and return a resId...

luca-itro commented 5 years ago

To prevent app crash you must define the smallIcon into the notification object param. However if it doesen't find the resource it fallback to a system resource that cannot be accessed in android Oreo. My pull seems to prevent this issue

tobiasmuecksch commented 5 years ago

I can confirm that beta .3 is NOT working on real Android 8.1 devices.

shaileshBhokare commented 4 years ago

To prevent app crash you must define the smallIcon into the notification object param. However if it doesen't find the resource it fallback to a system resource that cannot be accessed in android Oreo. Thank you

This works for me This is how my code looks now:

const notification = {
      id: 1234,
      text: 'This is notification',
      trigger: { at: new Date() },
      led: 'FF0000',
      smallIcon: 'res://mipmap-hdpi/ic_launcher.png',
      icon: 'res://mipmap-hdpi/ic_launcher.png',
      vibrate: true
    };
    this.localNotifications.schedule(notification);

res is a folder in android/app/src/main/res