cordova-plugin-local-notifications: Hundreds of crash reports from Google Play Console after deploying 0.9.0-beta3

WARNING: IF YOU IGNORE THIS TEMPLATE, WE’LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Provide a general summary of the issue.

Your Environment

  • Plugin version: 0.9.0-beta3
  • Platform: Android
  • OS version: 8.1 / 8.0
  • Device manufacturer / model: Mostly Pixels
  • Cordova version (cordova -v): 8.0.0
  • Cordova platform version (cordova platform ls): cordova-android 6.4.0
  • Plugin config
  • Ionic Version (if using Ionic) 3.9.2, using the plugin without ionic-native layer

Expected Behavior

Actual Behavior

After deploying an update to the play store a few days ago, I have been getting hundreds of crash reports from Google for devices running Android 8.1. and 8.0 (error attached below). No user complained yet, so I don’t know if the problem has any actual impact. I have tested the app on a Nexus 5X running android 8.1 as well as a few emulators, and I haven’t noticed any issues.

I am reporting this here just so you are aware, in case there is some actual issue.

Steps to Reproduce

Context

Debug logs

This is the error google has been reporting

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3194)
  at android.app.ActivityThread.-wrap17 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1672)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6494)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)

Caused by: java.lang.IllegalStateException: 
  at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:387)
  at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:372)
  at android.content.ContextWrapper.getSharedPreferences (ContextWrapper.java:167)
  at android.content.ContextWrapper.getSharedPreferences (ContextWrapper.java:167)
  at de.appplant.cordova.plugin.notification.Manager.getPrefs (Manager.java:399)
  at de.appplant.cordova.plugin.notification.Manager.getIds (Manager.java:206)
  at de.appplant.cordova.plugin.notification.Manager.getOptions (Manager.java:291)
  at de.appplant.cordova.plugin.notification.receiver.AbstractRestoreReceiver.onReceive (AbstractRestoreReceiver.java:64)
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3187)

Source code

This is a simplified version of the code I use to set notifications:

  setNotification(every:string, firstAt:Date){

    let text = this.notificationStrings.daily;

    let n:number = 30; // arbitrary large number
    
    let notifications = [];

    for (let i:number=0; i<n; i++){
      let theAt: Date = new Date(firstAt);
      if (every == 'minute'){
        theAt.setMinutes(theAt.getMinutes()+i);
      }else if (every == 'hour'){
        theAt.setHours(theAt.getHours()+i);
      }else if (every == 'day'){
        theAt.setDate(theAt.getDate()+i);
      }else if (every == 'week'){
        theAt.setDate(theAt.getDate()+i*7);
      }
      notifications.push(
        {
          id: i,
          title: this.notificationStrings.title,
          text: text,
          icon: "",
          sound: true,
          priority: 1,
          smallIcon: "res://"+this.notificationStrings.icon,
          foreground: true,
          wakeup: false,
          trigger:{
            at: theAt
          }
        }
      );

    }

    cordova.plugins.notification.local.cancelAll(
      () => {
        cordova.plugins.notification.local.schedule(notifications,
          () => {
            console.log("notification set ", firstAt, every);
          }
        );
      }
    );
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 33 (2 by maintainers)

Commits related to this issue

Most upvoted comments

To fix this crash.

  1. Open file: …/platforms/android/src/de/appplant/cordova/plugin/notification/receiver/AbstractRestoreReceiver.java

  2. Add import: import android.os.UserManager;

  3. Change strings 60-61 if (action.equals(ACTION_BOOT_COMPLETED) && SDK_INT >= 24) return;

to:

if (SDK_INT >= 24) { UserManager um = (UserManager) context.getSystemService(UserManager.class); if (um == null || um.isUserUnlocked() == false) return; }

Great, notifications are triggered even after device reboot ! (Tested on Android 4.4, 5.1, 6.0, 7.1, 8.1). Thx @Reactor13 😄

In may 2018 we wait Android 9 release. But still we don’t have Android 8 support in this plugin (the latest plugin with this functionality for Cordova).

@katzer I understand, that this plugin is free. But it is important for us. I can donate some money for you for support this plugin (pay for support in fact). Can we talk about it?

hi all, perhaps you can try this fork, it is more recent and still maintained: https://github.com/timkellypa/cordova-plugin-local-notifications

hope it helps. thanks.

After reboot notification is not come. Android: 7.1.2 Mobile: MI 5A.

@katzer Please, Please - fix this issue!!! Tell you price to fix it, please!

Google Pixel 2 (walleye), 4096MB RAM, Android 8.1

java.lang.RuntimeException: at android.app.ActivityThread.handleReceiver (ActivityThread.java:3194) at android.app.ActivityThread.-wrap17 (Unknown Source) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1672) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:164) at android.app.ActivityThread.main (ActivityThread.java:6494) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807) Caused by: java.lang.IllegalStateException: at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:387) at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:372) at android.content.ContextWrapper.getSharedPreferences (ContextWrapper.java:167) at android.content.ContextWrapper.getSharedPreferences (ContextWrapper.java:167) at de.appplant.cordova.plugin.notification.Manager.getPrefs (Manager.java:399) at de.appplant.cordova.plugin.notification.Manager.getIds (Manager.java:206) at de.appplant.cordova.plugin.notification.Manager.getOptions (Manager.java:291) at de.appplant.cordova.plugin.notification.receiver.AbstractRestoreReceiver.onReceive (AbstractRestoreReceiver.java:64) at android.app.ActivityThread.handleReceiver (ActivityThread.java:3187)

I am observing the same exception from my latest deployment as well. Even though users have not reported any issues, I am worried that the notification prevents the user from accessing the app.

Do you have any idea on when the plugin might be able to fully support Android 8?