emekalites / react-native-alarm-notification

schedule alarm and local notification in react-native
https://www.npmjs.com/package/react-native-alarm-notification
MIT License
225 stars 95 forks source link

Fixes error when setting snooze, repeat and vibration. #67

Closed Silver292 closed 4 years ago

Silver292 commented 4 years ago

When attempting to set an alarm using the repeat_interval, snooze_interval and vibration fields. i.e

export const alarmNotifData = {
  alarm_id: '22',
  channel: 'wakeup',
  data: { content: 'my notification id is 22' },
  fire_date: ReactNativeAN.parseDate(new Date()),
  message: 'Stand up',
  play_sound: true,
  repeat_interval: 10,
  schedule_type: 'once',
  snooze_interval: 3,
  title: 'Alarm',
  vibrate: true,
  vibration: 100
}

These errors are thrown:

2020-07-08 23:28:13.863 29955-29992/com.kegeltrainer W/Bundle: Key repeat_interval expected Integer but value was a java.lang.Double.  The default value 1 was returned.
2020-07-08 23:28:13.863 29955-29992/com.kegeltrainer W/Bundle: Attempt to cast generated internal exception:
    java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
        at android.os.BaseBundle.getInt(BaseBundle.java:873)
        at com.emekalites.react.alarm.notification.ANModule.sendNotification(ANModule.java:147)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:154)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
        at java.lang.Thread.run(Thread.java:761)
2020-07-08 23:28:13.863 29955-29992/com.kegeltrainer W/Bundle: Key snooze_interval expected Integer but value was a java.lang.Double.  The default value 1 was returned.
2020-07-08 23:28:13.863 29955-29992/com.kegeltrainer W/Bundle: Attempt to cast generated internal exception:
    java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
        at android.os.BaseBundle.getInt(BaseBundle.java:873)
        at com.emekalites.react.alarm.notification.ANModule.sendNotification(ANModule.java:154)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:154)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
        at java.lang.Thread.run(Thread.java:761)
2020-07-08 23:28:13.863 29955-29992/com.kegeltrainer W/Bundle: Key vibration expected Integer but value was a java.lang.Double.  The default value 100 was returned.
2020-07-08 23:28:13.863 29955-29992/com.kegeltrainer W/Bundle: Attempt to cast generated internal exception:
    java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
        at android.os.BaseBundle.getInt(BaseBundle.java:873)
        at com.emekalites.react.alarm.notification.ANModule.sendNotification(ANModule.java:162)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:154)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
        at java.lang.Thread.run(Thread.java:761)

Tested on:

    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-alarm-notification": "^1.4.6",
    Pixel 2 emulator running API 24

Related to #47, #65. These changes parse the settings as doubles then cast them back to ints