{"id":23895234,"url":"https://github.com/emekalites/react-native-alarm-notification","last_synced_at":"2025-04-07T18:11:26.030Z","repository":{"id":22166067,"uuid":"95035630","full_name":"emekalites/react-native-alarm-notification","owner":"emekalites","description":"schedule alarm and local notification in react-native","archived":false,"fork":false,"pushed_at":"2024-09-11T21:43:51.000Z","size":1657,"stargazers_count":228,"open_issues_count":18,"forks_count":96,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T17:15:39.392Z","etag":null,"topics":["alarm","android","notification","react-native","react-native-alarm","scheduling"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-native-alarm-notification","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emekalites.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-21T18:46:45.000Z","updated_at":"2025-03-25T11:21:38.000Z","dependencies_parsed_at":"2024-01-30T14:52:27.669Z","dependency_job_id":"85db813d-1de1-4cd9-a4e2-e6cea036afe2","html_url":"https://github.com/emekalites/react-native-alarm-notification","commit_stats":{"total_commits":124,"total_committers":16,"mean_commits":7.75,"dds":0.217741935483871,"last_synced_commit":"6bbbd36825b10826c67c27d6ac26b47227bd9643"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emekalites%2Freact-native-alarm-notification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emekalites%2Freact-native-alarm-notification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emekalites%2Freact-native-alarm-notification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emekalites%2Freact-native-alarm-notification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emekalites","download_url":"https://codeload.github.com/emekalites/react-native-alarm-notification/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704569,"owners_count":20982298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alarm","android","notification","react-native","react-native-alarm","scheduling"],"created_at":"2025-01-04T15:53:34.436Z","updated_at":"2025-04-07T18:11:25.996Z","avatar_url":"https://github.com/emekalites.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Native Alarm Notification\n\n[![npm version](https://badge.fury.io/js/react-native-alarm-notification.svg)](https://badge.fury.io/js/react-native-alarm-notification)\n[![npm downloads](https://img.shields.io/npm/dt/react-native-alarm-notification.svg)](https://badge.fury.io/js/react-native-alarm-notification)\n\n\n## ***** Maintaner/Collaborator Needed as I am too busy to manage the issues and add new versions *****\n\n\n## Installing (React Native \u003e= 0.60.0)\n\n```sh\nnpm install react-native-alarm-notification --save\n```\n\nor\n\n```sh\nyarn add react-native-alarm-notification\n```\n\nIf you are using react-native version 0.60 or higher you don't need to link [react-native-alarm-notification](https://github.com/emekalites/react-native-alarm-notification). The package is automatically linked when building the app. All you need to do after installing package is:\n\nFor iOS pod installation:\n\n```bash\nnpx pod-install\n```\n\nor \n\n```bash\ncd ios \u0026\u0026 pod install\n```\n\nFor android, the package will be linked automatically on build.\n\n**_ IMPORTANT _**\n\nIf your app crashes on **Android**, it could probably mean auto linking didn't work. You will need to make the following changes:\n\n\u003cdetails\u003e\n    \u003csummary\u003eShow steps\u003c/summary\u003e\n\n**android/app/src/main/java/\\\u003cAppName\\\u003e/MainApplication.java**\n\n- add `import com.emekalites.react.alarm.notification.ANPackage;` on the imports section\n- add `packages.add(new ANPackage());` in `List\u003cReactPackage\u003e getPackages()`;\n\n**android/app/build.gradle**\n\nadd `implementation project(':react-native-alarm-notification')` in the `dependencies` block\n\n**android/settings.gradle**\n\nadd:\n\n```\ninclude ':react-native-alarm-notification'\nproject(':react-native-alarm-notification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-alarm-notification/android')\n\n```\n\u003c/details\u003e\n\n## Installing (React Native \u003c= 0.59.x)\n\n\u003cdetails\u003e\n    \u003csummary\u003eExpand\u003c/summary\u003e\n\n```sh\nnpm install react-native-alarm-notification --save\n```\n\nor\n\n```sh\nyarn add react-native-alarm-notification\n```\nUse `react-native link` to add the library to your project:\n\n```sh\nreact-native link react-native-alarm-notification\n```\n\u003c/details\u003e\n\n## iOS manual Installation\n\n\u003cdetails\u003e\n    \u003csummary\u003eExpand\u003c/summary\u003e\n\n**\u003e In your `AppDelegate.h`**\n\nAdd at the top of the file:\n\n```objective-c\n#import \u003cUserNotifications/UNUserNotificationCenter.h\u003e\n```\n\nThen, add the 'UNUserNotificationCenterDelegate' to protocols:\n\n```diff\n- @interface AppDelegate : UIResponder \u003cUIApplicationDelegate, RCTBridgeDelegate\u003e\n+ @interface AppDelegate : UIResponder \u003cUIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate\u003e\n```\n\n**\u003e In your `AppDelegate.m`**\n\nAdd at the top of the file:\n\n```objective-c\n#import \u003cRnAlarmNotification.h\u003e\n#import \u003cUserNotifications/UNUserNotificationCenter.h\u003e\n```\n\nThen, add the following lines:\n\n```objective-c\n- (void)userNotificationCenter:(UNUserNotificationCenter *)center\n       willPresentNotification:(UNNotification *)notification withCompletionHandler: (void (^)(UNNotificationPresentationOptions options))completionHandler {\n  [RnAlarmNotification didReceiveNotification:notification];\n  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);\n}\n\n\n- (void)userNotificationCenter:(UNUserNotificationCenter *)center\ndidReceiveNotificationResponse:(UNNotificationResponse *)response\n         withCompletionHandler:(void (^)(void))completionHandler  API_AVAILABLE(ios(10.0)){\n    [RnAlarmNotification didReceiveNotificationResponse:response];\n    completionHandler();\n}\n```\n\nAnd then in your AppDelegate implementation, add the following:\n\n```objective-c\n@implementation AppDelegate\n\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n{\n  ...\n  \n  // Define UNUserNotificationCenter\n  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];\n  center.delegate = self;\n  \n  return YES;\n}\n```\n\nTo play sound in the background, make sure to add the following to the `Info.plist` file.\n\n```Info.plist\n\u003ckey\u003eUIBackgroundModes\u003c/key\u003e\n\u003carray\u003e\n    \u003cstring\u003eaudio\u003c/string\u003e\n\u003c/array\u003e\n```\n\u003c/details\u003e\n\n## Android manual Installation\n\n\u003cdetails\u003e\n    \u003csummary\u003eExpand\u003c/summary\u003e\n\n**\u003e In your `AndroidManifest.xml`**\n\n```xml\n    .....\n    \u003cuses-permission android:name=\"android.permission.INTERNET\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.VIBRATE\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.WAKE_LOCK\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.RECEIVE_BOOT_COMPLETED\" /\u003e\n\n    \u003capplication ....\u003e\n        \u003creceiver\n            android:name=\"com.emekalites.react.alarm.notification.AlarmReceiver\"\n            android:enabled=\"true\"\n            android:exported=\"true\"\u003e\n            \u003cintent-filter\u003e\n                \u003caction android:name=\"ACTION_DISMISS\" /\u003e\n                \u003caction android:name=\"ACTION_SNOOZE\" /\u003e\n            \u003c/intent-filter\u003e\n        \u003c/receiver\u003e\n\n        \u003creceiver\n            android:name=\"com.emekalites.react.alarm.notification.AlarmDismissReceiver\"\n            android:enabled=\"true\"\n            android:exported=\"true\" /\u003e\n\n        \u003creceiver\n            android:name=\"com.emekalites.react.alarm.notification.AlarmBootReceiver\"\n            android:directBootAware=\"true\"\n            android:enabled=\"false\"\n            android:exported=\"true\"\u003e\n            \u003cintent-filter\u003e\n                \u003caction android:name=\"android.intent.action.BOOT_COMPLETED\" /\u003e\n                \u003caction android:name=\"android.intent.action.QUICKBOOT_POWERON\" /\u003e\n                \u003caction android:name=\"com.htc.intent.action.QUICKBOOT_POWERON\" /\u003e\n                \u003caction android:name=\"android.intent.action.LOCKED_BOOT_COMPLETED\" /\u003e\n            \u003c/intent-filter\u003e\n        \u003c/receiver\u003e\n     .....\n```\n\u003c/details\u003e\n\n\n## Alarm Notification Data\n\n| Prop                              | Description                                                                                                                                                                                                                                                                                                             | Default                     |\n| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |\n| **`auto_cancel`**                 | Make this notification automatically dismissed when the user touches it. `[boolean]`                                                                                                                                                                                                                                    | `true`                      |\n| **`channel (Android only)`**      | **Required:** - Specifies the channel the notification should be delivered on.. `[string]`                                                                                                                                                                                                                              | `\"my_channel_id\"`           |\n| **`color (Android only)`**        | **Required:** Sets notification color. `[color]`                                                                                                                                                                                                                                                                        | `\"red\"`                     |\n| **`data`**                        | You can add any additional data that is important for the notification.                                                                                                                                                                                                                                                 | `data: { foo: \"bar\" }`      |\n| **`fire_date`**                   | **Required:** Set date for Alarm to get triggered. eg `'04-03-2020 00:00:00'`. Should be a date in the future .                                                                                                                                                                                                         | _None_                      |\n| **`has_button`**                  | Show snooze and dismiss buttons in notification. `[boolean]`                                                                                                                                                                                                                                                            | `false`                     |\n| **`large_icon (Android Only)`**   | Add a large icon to the notification content view. eg `\"ic_large_icon\"`. PS: make sure to add the file in your mipmap folders `[project_root]/android/app/src/main/res/mipmap*`                                                                                                                                         | _None_                      |\n| **`loop_sound`**                  | Play sound continuously until you decide to stop it. `[boolean]`                                                                                                                                                                                                                                                        | `false`                     |\n| **`message`**                     | **Required:** Add Notification message.                                                                                                                                                                                                                                                                                 | `\"My Notification Message\"` |\n| **`play_sound`**                  | Play alarm notification sound. `[boolean]`                                                                                                                                                                                                                                                                              | `true`                      |\n| **`schedule_type`**               | **Required:** Type of alarm schedule. `\"once\"` (to show alarm once) or `\"repeat\"` (to display alarm after set repeat_interval)                                                                                                                                                                                          | `\"once\"`                    |\n| **`repeat_interval`**             | Interval set to repeat alarm if schedule_type is \"repeat\". `[minutely, hourly, daily, weekly]`                                                                                                                                                                                                                                        | `\"hourly\"`                         |\n| **`interval_value`**             | Set interval_value if repeat_interval is minutely and hourly. `[number]`                                                                                                                                                                                                                                        | `1`                         |\n| **`small_icon`**                  | **Required:** Set the small icon resource, which will be used to represent the notification in the status bar. eg `\"ic_launcher\"`. PS: make sure to add the file in your mipmap folders `[project_root]/android/app/src/main/res/mipmap*`                                                                               | `\"ic_launcher\"`             |\n| **`snooze_interval`**             | Interval set to show alarm after snooze button is tapped. `[number]` in minutes                                                                                                                                                                                                                                         | `1`                         |\n| **`sound_name`**                  | Set audio file to play when alarm is triggered. example `\"sound_name.mp3\"`. Add the file in your res/raw folder `[project_root]/android/app/src/main/res/raw/` for android and in your ios folder `[project_root]/ios/` for iOS. PS: After adding file in your iOS folder, open your application in xcode and drag your audio file into your project.                                                                                                                          | _None_                      |\n| **`sound_names`**                 | Set multiple audio files to play when alarm is triggered, each file will be picked to play at random. Separate files with a comma (`,`) example `\"sound_name1.mp3,sound_name2.mp3\"`. PS: make sure to add the files in your res/raw folder `[project_root]/android/app/src/main/res/raw/` | _None_                      |\n| **`tag`**                         | Add a tag id to notification.                                                                                                                                                                                                                                                                                           | _None_                      |\n| **`ticker`**                      | Set the \"ticker\" text which is sent to accessibility services.. `[String]`                                                                                                                                                                                                                                              | _None_                      |\n| **`title`**                       | **Required:** Add a title to notification.                                                                                                                                                                                                                                                                              | `\"My Notification Title\"`   |\n| **`vibrate`**                     | Set vibration when alarm is triggered. `[boolean]`                                                                                                                                                                                                                                                                      | `true`                      |\n| **`vibration`**                   | Set number of milliseconds to vibrate. `[number]`                                                                                                                                                                                                                                                                       | `100`                       |\n| **`use_big_text (Android only)`** | Set notification message style as big text. `[boolean]`                                                                                                                                                                                                                                                                 | `false`                     |\n| **`volume`**                   | Set volume. `[number between 0.0 and 1.0]`                                                                                                                                                                                                                                                                       | `0.5`                       |\n| **`bypass_dnd (Android only)`**                   | Sets whether or not notifications posted to this channel can interrupt the user                                                                                                                                                                                                                                                                        | `false`                       |\n\n## Usage\n\n```javascript\nimport ReactNativeAN from 'react-native-alarm-notification';\n\nconst fireDate = ReactNativeAN.parseDate(new Date(Date.now() + 1000));     // set the fire date for 1 second from now\nor\nconst fireDate = '01-01-2060 00:00:00';\t\t\t  // set exact date time | Format: dd-MM-yyyy HH:mm:ss\n\nconst alarmNotifData = {\n\ttitle: \"My Notification Title\",\n\tmessage: \"My Notification Message\",\n\tchannel: \"my_channel_id\",\n\tsmall_icon: \"ic_launcher\",\n\n\t// You can add any additional data that is important for the notification\n\t// It will be added to the PendingIntent along with the rest of the bundle.\n\t// e.g.\n  \tdata: { foo: \"bar\" },\n};\n\nclass App extends Component {\n\t...\n\n    async method(){\n        //Schedule Future Alarm\n        const alarm = await ReactNativeAN.scheduleAlarm({ ...alarmNotifData, fire_date: fireDate });\n        console.log(alarm); // { id: 1 }\n\n        //Delete Scheduled Alarm\n        ReactNativeAN.deleteAlarm(alarm.id);\n\n        //Delete Repeating Alarm\n        ReactNativeAN.deleteRepeatingAlarm(alarm.id);\n\n        //Stop Alarm\n        ReactNativeAN.stopAlarmSound();\n\n        //Send Local Notification Now\n        ReactNativeAN.sendNotification(alarmNotifData);\n\n        //Get All Scheduled Alarms\n        const alarms = await ReactNativeAN.getScheduledAlarms();\n\n        //Clear Notification(s) From Notification Center/Tray\n        ReactNativeAN.removeFiredNotification(alarm.id);\n        ReactNativeAN.removeAllFiredNotifications();\n    }\n\n\t...\n}\n```\n\n## Handle notification intent\n\n```java\n\n...\nimport android.content.Intent;\nimport android.os.Bundle;\n\nimport com.emekalites.react.alarm.notification.BundleJSONConverter;\nimport com.facebook.react.ReactActivity;\nimport com.facebook.react.modules.core.DeviceEventManagerModule;\n\nimport org.json.JSONObject;\n...\n\npublic class MainActivity extends ReactActivity {\n    ...\n\n    @Override\n    public void onNewIntent(Intent intent) {\n        super.onNewIntent(intent);\n        try {\n            Bundle bundle = intent.getExtras();\n            if (bundle != null) {\n                JSONObject data = BundleJSONConverter.convertToJSON(bundle);\n                getReactInstanceManager().getCurrentReactContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(\"OnNotificationOpened\", data.toString());\n            }\n        } catch (Exception e) {\n            System.err.println(\"Exception when handling notification opened. \" + e);\n        }\n    }\n\n}\n```\n\n## Listener for notifications\n\n```js\nimport { NativeEventEmitter, NativeModules } from 'react-native';\n\nconst { RNAlarmNotification } = NativeModules;\nconst RNAlarmEmitter = new NativeEventEmitter(RNAlarmNotification);\n\nconst dismissSubscription = RNAlarmEmitter.addListener(\n    'OnNotificationDismissed', (data) =\u003e console.log(JSON.parse(e));\n);\n\nconst openedSubscription = RNAlarmEmitter.addListener(\n    'OnNotificationOpened', (data) =\u003e console.log(JSON.parse(e));\n);\n\n...\n\n// unsubscribe, typically in componentWillUnmount\ndismissSubscription.remove();\nopenedSubscription.remove();\n```\n\n## iOS Permissions\n\n```js\nimport ReactNativeAN from 'react-native-alarm-notification';\n\n// check if notification permissions has been granted for iOS\nReactNativeAN.checkPermissions((permissions) =\u003e {\n\tconsole.log(permissions);\n});\n\n// Request iOS permissions\nReactNativeAN.requestPermissions({\n\talert: true,\n\tbadge: true,\n\tsound: true,\n}).then(\n\t(data) =\u003e {\n\t\tconsole.log('RnAlarmNotification.requestPermissions', data);\n\t},\n\t(data) =\u003e {\n\t\tconsole.log('RnAlarmNotification.requestPermissions failed', data);\n\t}\n);\n```\n\n## Some features are missing\n\nThis module is customized to help with scheduling and sending notifications (local) in react-native. A couple of helpful features may be missing but hopefully they can be added as time goes on.\n\nNOTE: If you need a react-native module that takes care of Firebase Cloud Messaging, you could use [react-native-firebase](https://github.com/invertase/react-native-firebase)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femekalites%2Freact-native-alarm-notification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femekalites%2Freact-native-alarm-notification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femekalites%2Freact-native-alarm-notification/lists"}