Cordova-plugin-local-notifications: App crash android oreo

Created on 26 Apr 2019  路  5Comments  路  Source: katzer/cordova-plugin-local-notifications

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

  • Plugin version: 0.9.0-beta.2
  • Platform: Android
  • OS version: 8.1 Oreo
  • Device manufacturer / model: Mediacom 7BY
  • Cordova version: 9.0.0
  • Cordova platform version: android 8.0.0

Steps to Reproduce

simply use the code above onDeviceReady

Debug logs

logcat.txt

Most helpful comment

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

All 5 comments

make sure your plugin version is beta._3_ or later

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...

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

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

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

Was this page helpful?
0 / 5 - 0 ratings