WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!
Provide a general summary of the issue.
cordova -v
): 8.0.0cordova platform ls
): cordova-android 6.4.0After 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.
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)
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);
}
);
}
);
}
@katzer any idea about this?
the crash reports keep on coming, and they involve devices running Android 8.0 and 8.1
@alesgenova the plugin still does not support Android 8, just basic support because they introduced breaking changes and a fully new concept. That will come into the plugin as well with 0.9-rc.0 but might come along with breaking changes compared to 0.9-beta
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?
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?
@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 have reproduce this bug.
This crash occurs when device starting or after reboot.
Scheduled notifications WILL NOT FIRE after device reboot.
04-17 00:39:31.251 879-902/? I/ActivityManager: Start proc 1830:ru.airbits.ihamster/u0a185 for broadcast ru.airbits.ihamster/de.appplant.cordova.plugin.localnotification.RestoreReceiver
04-17 00:39:31.349 1830-1830/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: ru.airbits.ihamster, PID: 1830
java.lang.RuntimeException: Unable to start receiver de.appplant.cordova.plugin.localnotification.RestoreReceiver: java.lang.IllegalStateException: SharedPreferences in credential encrypted storage are not available until after user is unlocked
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3194)
at android.app.ActivityThread.-wrap17(Unknown Source:0)
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: SharedPreferences in credential encrypted storage are not available until after user is unlocked
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)
at android.app.ActivityThread.-wrap17(Unknown Source:0)Â
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)Â
To fix this crash.
Open file:
../platforms/android/src/de/appplant/cordova/plugin/notification/receiver/AbstractRestoreReceiver.java
Add import:
import android.os.UserManager;
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;
}
@Reactor13 This looks like it could be a welcome pull request!
On Apr 17, 2018, at 7:21 AM, Reactor13 notifications@github.com wrote:
To fix this crash.
Open file:
../platforms/android/src/de/appplant/cordova/plugin/notification/receiver/AbstractRestoreReceiver.javaAdd import:
import android.os.UserManager;Change strings 60-61
if ((action.equals(ACTION_BOOT_COMPLETED) || action.equals(LOCKED_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; }
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/katzer/cordova-plugin-local-notifications/issues/1541#issuecomment-382010284, or mute the thread https://github.com/notifications/unsubscribe-auth/AHVytDQyhAnmYpFvtOUJPRMEISeCERAQks5tpfpggaJpZM4SJxco.
similar problem for my app:
google play console reports:
java.lang.ClassCastException:
at de.appplant.cordova.plugin.notification.Request.getMatchingComponents (Request.java:233)
at de.appplant.cordova.plugin.notification.Request.buildTrigger (Request.java:172)
at de.appplant.cordova.plugin.notification.Request.
at de.appplant.cordova.plugin.localnotification.LocalNotification.schedule (LocalNotification.java:270)
at de.appplant.cordova.plugin.localnotification.LocalNotification.access$400 (LocalNotification.java:62)
at de.appplant.cordova.plugin.localnotification.LocalNotification$1.run (LocalNotification.java:146)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607)
at java.lang.Thread.run (Thread.java:761)
@Reactor13 Do you still use your fix without any side effect? Or have you found another solution?
@jpierront Yes, i still use my fix without any side effect and waiting for plugin update...
@jpierront as i see - you have forgot this in your commit:
import android.os.UserManager;
Thanks for your help :) I'll try it soon !
Great, notifications are triggered even after device reboot ! (Tested on Android 4.4, 5.1, 6.0, 7.1, 8.1).
Thx @Reactor13 :D
When can this ticket got released?
@Reactor13 Could you explain how your proposed change properly fixes the issue? If I understand correctly, the onReceive() handler is used to restore notifications on reboot. Your addition will prevent a crash when Manager.getInstance() is called, but by returning early it will also skip the code that restores notifications on reboot. Or isn't that piece needed on API >= 24?
hey @Reactor13 , thanks for the code, it worked ok for me using android 8, 7 e 5 tested on Samsung J6, redmi note e redmi 3.
Just to complement, repeated notifications are not working os Android 8 with the @Reactor13 fix, still working on Android 5.
After reboot notification is not come.
Android: 7.1.2
Mobile: MI 5A.
Any update on notification after reboot ?
Hello,
Is there any "official" release that fixes this issue?
Thank you,
Louis
i had install cordova plugin add [email protected]
and check with the same,
set notification then reboot my device but notification not come at scheduled time.
I don't know how to resolve this.
@husainsr
You must use the master version of this plugin to fix the issue.
Can someone please build a new release Version? I generally don't like to install from Git Branches directly. @dpa99c
@husainsr
You must use the master version of this plugin to fix the issue.
I have the same crash logs, and I'm using the beta-3.
What is the difference in term of features between the master and the beta 3 ? (I don't want to switch if there's a difference)
We just released an updated version of an app that uses 0.9.0-beta.3, and we have started receiving significant numbers of the same exceptions. It does not sound like the previously proposed fix is complete, as after reboot notifications are no longer received.
I'm not an Android native programmer, I usually use Ionic, so I'm not well versed in the native APIs here. Does anyone know how to fix this issue, and still ensure that previously scheduled local notifications will work after reboot?
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.
@rahmadid Thank you for the recommendation. I'll take a look.
Hi @rahmadid I tried this fork but I'm getting buil errors such as:
/.../platforms/android/app/src/main/java/de/appplant/cordova/plugin/notification/Builder.java:498: error: package NotificationCompat does not exist
NotificationCompat.Builder builder = Notification.getCachedBuilder(key);
And 99 other errors of that type. Did I miss something?
@aleygues Maybe because that plugin uses androidx. If you haven't migrated to androidx yet, you can try these two plugins for easy migration:
https://github.com/dpa99c/cordova-plugin-androidx
https://github.com/dpa99c/cordova-plugin-androidx-adapter
Thanks.
Hi @rahmadid thanks! I'll give it a try
Hi @rahmadid I just tried by bumping my cordova app from Cordova Android 8 to 9. By enabling AndroidX, this plugin build successfully, unfortunetly, some other plugins (including Phonegap Push, Camera and File Opener) seems to by incompatible with AndroidX.
I'm still stuck, but not for the same reason ^.^. Thanks for the help!
As @rahmadid mentioned, I would suggest to migrate to https://github.com/timkellypa/cordova-plugin-local-notifications. I have tested with that version of the plugin and the crashes have dropped considerably.
Most helpful comment
To fix this crash.
Open file:
../platforms/android/src/de/appplant/cordova/plugin/notification/receiver/AbstractRestoreReceiver.java
Add import:
import android.os.UserManager;
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; }