Closed FahmiChaar closed 1 year ago
This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.
Please see the Contributing Guide for how to create a Code Reproduction.
Thanks! Ionitron π
@jcesarmobile i add code reproduction, capacitor testApp crash if i click schedule now button
please, don't ping me, and please, provide your own app, I can't reproduce on our test app.
Repo to reproduce the app crash https://github.com/FahmiChaar/capacitor-local-notifications-demo
Thanks for the sample app, but I get this error
Scheduled time must be after current time because because between calling
at: new Date()
and the code arriving on the native side there are a few milliseconds of difference. If I remove the at so it gets fired right away, there is no crash, and if I change the at to fire in 10 seconds it doesn't crash neither.
Which package manager are you using?
Did you run npx cap sync
after updating the plugin to 4.x?
Do you see this lines of code in the LocalNotificationManager.java
class?
https://github.com/ionic-team/capacitor-plugins/blob/96c5430f9bae13b54f3897dd1bffad030bfe3a3b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java#L330-L332
Thanks for your reply
even after remove the "at" attribute the app keeps crashing
npx cap sync
If there is no at/on/every, it fires right away without creating a Pending Intent, so it shouldn't crash.
And if that line is there, FLAG_MUTABLE is being added, so shouldn't crash with a proper at/on/every neither.
Can you fix your app so it works and also provide the full crash log?
i remove the "schedule" attribute from the notification object and this is the full crash log
--------- beginning of system
2022-10-24 19:40:16.947 12205-12205/com.test.ln I/Capacitor/Console: File: http://localhost/ - Line 231 - Msg: undefined
2022-10-24 19:40:16.947 12205-12205/com.test.ln I/Capacitor/Console: File: http://localhost/ - Line 231 - Msg: undefined
2022-10-24 19:40:16.947 12205-12205/com.test.ln I/Capacitor/Console: File: http://localhost/ - Line 231 - Msg: undefined
2022-10-24 19:40:16.948 12205-12205/com.test.ln V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 69107722, pluginId: LocalNotifications, methodName: schedule
2022-10-24 19:40:16.948 12205-12205/com.test.ln V/Capacitor: callback: 69107722, pluginId: LocalNotifications, methodName: schedule, methodData: {"notifications":[{"title":"Local notifications","body":"Local Notifications Test app","id":1666636816947,"channelId":"1666636816938"}]}
2022-10-24 19:40:16.952 12205-12285/com.test.ln D/CompatibilityChangeReporter: Compat change id reported: 160794467; UID 10196; state: ENABLED
2022-10-24 19:40:16.954 12205-12285/com.test.ln E/Capacitor: Serious error executing plugin
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:125)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:721)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: java.lang.IllegalArgumentException: com.test.ln: Targeting S+ (version 10000 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at com.capacitorjs.plugins.localnotifications.LocalNotificationManager.cancelTimerForNotification(LocalNotificationManager.java:413)
at com.capacitorjs.plugins.localnotifications.LocalNotificationManager.schedule(LocalNotificationManager.java:148)
at com.capacitorjs.plugins.localnotifications.LocalNotificationsPlugin.schedule(LocalNotificationsPlugin.java:66)
... 9 more
--------- beginning of crash
2022-10-24 19:40:16.956 12205-12285/com.test.ln E/AndroidRuntime: FATAL EXCEPTION: CapacitorPlugins
Process: com.test.ln, PID: 12205
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:730)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:125)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:721)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)Β
at android.os.Handler.handleCallback(Handler.java:938)Β
at android.os.Handler.dispatchMessage(Handler.java:99)Β
at android.os.Looper.loopOnce(Looper.java:201)Β
at android.os.Looper.loop(Looper.java:288)Β
at android.os.HandlerThread.run(HandlerThread.java:67)Β
Caused by: java.lang.IllegalArgumentException: com.test.ln: Targeting S+ (version 10000 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at com.capacitorjs.plugins.localnotifications.LocalNotificationManager.cancelTimerForNotification(LocalNotificationManager.java:413)
at com.capacitorjs.plugins.localnotifications.LocalNotificationManager.schedule(LocalNotificationManager.java:148)
at com.capacitorjs.plugins.localnotifications.LocalNotificationsPlugin.schedule(LocalNotificationsPlugin.java:66)
... 9 more
2022-10-24 19:40:16.988 12205-12236/com.test.ln D/EGL_emulation: app_time_stats: avg=916.42ms min=2.45ms max=11696.42ms count=13
2022-10-24 19:40:17.030 12205-12205/com.test.ln V/Capacitor/AppPlugin: Notifying listeners for event pause
2022-10-24 19:40:17.031 12205-12205/com.test.ln D/Capacitor/AppPlugin: No listeners found for event pause
2022-10-24 19:40:17.031 12205-12205/com.test.ln D/Capacitor: App paused
2022-10-24 19:40:17.297 12205-12205/com.test.ln D/Capacitor/AppPlugin: Firing change: false
2022-10-24 19:40:17.298 12205-12205/com.test.ln V/Capacitor/AppPlugin: Notifying listeners for event appStateChange
2022-10-24 19:40:17.298 12205-12205/com.test.ln D/Capacitor/AppPlugin: No listeners found for event appStateChange
2022-10-24 19:40:17.298 12205-12205/com.test.ln D/Capacitor: App stopped
2022-10-24 19:40:17.319 12205-12205/com.test.ln D/Capacitor: App destroyed
as you can see in the error log the methodData send to native side is without "schedule/at..."
methodName: schedule, methodData: {"notifications":[{"title":"Local notifications","body":"Local Notifications Test app","id":1666636816947,"channelId":"1666636816938"}]}
This looks like a bug on the emulator you are using.
FLAG_MUTABLE
is required for Android 12+, but you say the problem is on an Android 11 emulator.
For Android 11 FLAG_MUTABLE
is not defined, so can't be used, so it makes sense that it's not there as the code checks for android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
and Android 11 doesn't satisfy that requirement, so no flag is added.
Can you try creating a different emulator or testing on a real Android 11 device?
i'm sorry the emulator has android 12, but I think the problem is in the emulator because the users who downloaded the update from the play store the app no longer crash so i will close this issue
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.
Bug Report
Plugin(s)
local-notifications
Capacitor Version
Platform(s)
android
Current Behavior
App crash when scheduling a notification on android S+ devices
Expected Behavior
To not crash
Code Reproduction
https://github.com/ionic-team/capacitor-testapp/blob/main/src/components/LocalNotificationTest.tsx
Other Technical Details
@capacitor/local-notifications@4.1.2
Additional Context
Capacitor: Caused by: java.lang.IllegalArgumentException: com.capacitorjs.app.testapp: Targeting S+ (version 10000 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.