voximplant / react-native-foreground-service

React native module to start foreground service on android
MIT License
159 stars 91 forks source link

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

Open gmccobb opened 4 years ago

gmccobb commented 4 years ago

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,

tapioko commented 4 years ago

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

The fix looks good to me.

hazelf42 commented 3 years ago

+1 having this issue. Hope this gets merged