The following crash is reported on my google play console, once upgrading to capacitor 3.
java.lang.RuntimeException:
at android.app.ActivityThread.handleReceiver (ActivityThread.java:4452)
at android.app.ActivityThread.access$1500 (ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2159)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:246)
at android.app.ActivityThread.main (ActivityThread.java:8506)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)
Caused by: java.lang.ClassCastException:
at android.app.SharedPreferencesImpl.getString (SharedPreferencesImpl.java:302)
at com.capacitorjs.plugins.localnotifications.NotificationStorage.getSavedNotificationAsJSObject (NotificationStorage.java:95)
at com.capacitorjs.plugins.localnotifications.NotificationStorage.getSavedNotification (NotificationStorage.java:112)
at com.capacitorjs.plugins.localnotifications.LocalNotificationRestoreReceiver.onReceive (LocalNotificationRestoreReceiver.java:29)
at android.app.ActivityThread.handleReceiver (ActivityThread.java:4443)
This is how I use the plugin:
PushNotifications.addListener('pushNotificationReceived', (notification: PushNotificationSchema) => {
if(deviceService.getPlatform() === "android" ) {
this.sendLocalNotification(notification);
}
});
sendLocalNotification(notification: PushNotificationSchema){
if(typeof(notification.title) !== 'undefined'
&& typeof(notification.body) !== 'undefined'){
LocalNotifications.schedule({
notifications: [{
title: notification.title ,
body: notification.body,
id: new Date().getUTCMilliseconds(),
schedule: {
at: new Date(Date.now() + 1000)
},
extra: notification.data,
channelId: notification.data.channel_id
}]
});
}
}
Some important Notes:
- I use local notifications for displaying FCM push notifications on Android when the app is foreground.
2.Downgrading to capacitor 2.2.0 prevents this crash.
1. What is causing this exception and how can I prevent it?
2. Is it a ‘real’ crash - meaning something the user is experiencing ? or is it an exception that is reported in the background?
I’ll appreciate any help as this is preventing me from releasing the app.