react-native-foreground-service icon indicating copy to clipboard operation
react-native-foreground-service copied to clipboard

java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer

Open gmccobb opened this issue 5 years ago • 2 comments

The following exception is thrown when starting the foreground service:

java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer at android.os.BaseBundle.getInt(BaseBundle.java:1041) at android.os.BaseBundle.getInt(BaseBundle.java:1023) at com.voximplant.foregroundservice.NotificationHelper.buildNotification(NotificationHelper.java:99) at com.voximplant.foregroundservice.VIForegroundService.onStartCommand(VIForegroundService.java:31) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4087) at android.app.ActivityThread.access$1800(ActivityThread.java:219) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

At line 99 of NotificationHelper.java:

int priorityInt = notificationConfig.containsKey("priority") ? notificationConfig.getInt("priority"): Notification.PRIORITY_HIGH;

The exception is thrown because there must be explicit cast to int when downcasting from double.

The proposed fix is to replace line 99 with the following:

int priorityInt = notificationConfig.containsKey("priority") ? (int)notificationConfig.getDouble("priority"): Notification.PRIORITY_HIGH;

I am submitting a PR with the above proposed fix.

Thank you,

gmccobb avatar Jan 14 '20 16:01 gmccobb

How does the double get in there? Sometimes this occurs when I profile the application.

The fix looks good to me.

tapioko avatar Apr 21 '20 12:04 tapioko

+1 having this issue. Hope this gets merged

hazelf42 avatar Feb 02 '21 23:02 hazelf42