npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-alarm-manager

v1.2.1

Published

Alarm manager for React Native

Downloads

336

Readme

react-native-alarm-manager

npm version install size react-native

Alarm manager for React Native

Table of Contents

Installation

Adding the package

npm

$ npm install react-native-alarm-manager

yarn

$ yarn add react-native-alarm-manager

Manipulating codes in your project

Check android SDK

This package is compiled with Android SDK Platform 29.
Your project SDK version doesn't matter.
Android SDK Platform 29 must be installed.

Register components

Go to AndroidManifest.xml and register the service and receiver.

<manifest ... >
    <application ... >
      <activity ... >
      </activity>
      
      <!-- Add the following code -->
      <service android:name="com.baekgol.reactnativealarmmanager.util.AlarmService" android:enabled="true" android:exported="false" />
      <receiver android:name="com.baekgol.reactnativealarmmanager.util.AlarmReceiver" android:enabled="true" android:exported="false" />
      <receiver android:name="com.baekgol.reactnativealarmmanager.util.BootReceiver" android:enabled="false" android:exported="false" >
          <intent-filter android:priority="999">
              <action android:name="android.intent.action.BOOT_COMPLETED" />
          </intent-filter>
      </receiver>
      
    </application>
</manifest>

Overriding MainActivity methods

Go to MainActivity.java and override the onCreate and createReactActivityDelegate methods as follows.
It can work properly during the process of calling parameters and rebooting the android with alarm functions.

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  ComponentName receiver = new ComponentName(this, BootReceiver.class);
  PackageManager packageManager = this.getPackageManager();

  packageManager.setComponentEnabledSetting(receiver,
          PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
          PackageManager.DONT_KILL_APP);
}

@Override
protected ReactActivityDelegate createReactActivityDelegate() {
  return new ReactActivityDelegate(this, getMainComponentName()){
    @Nullable
    @Override
    protected Bundle getLaunchOptions() {
      Intent intent = getIntent();
      Bundle bundle = intent.getExtras();

      if(intent.getBooleanExtra("notiRemovable", true))
        AlarmModule.stop(this.getContext());

      return bundle;
    }
  };
}

Create resource directory

Configure your project's resource directory.
This is a necessary process to apply the alarm sound and notification icon.

project/app/src/main/res/raw       // alarm sound
project/app/src/main/res/drawable  // notification icon

Usage

First, import the module to use the alarm function.

import Alarm from 'react-native-alarm-manager';

Props

|Prop|Type|Description|Note| |-|-|-|-| |alarm_id|Number|Unique value of an alarm.|Auto Increment| |alarm_time|String|Value to set the alarm time.|HH:mm:00| |alarm_title|String|Title of notification.|Nullable| |alarm_text|String|Text of notification.|Nullable| |alarm_sound|String|Sound that rings when the alarm is activated.|Exclude file extensions| |alarm_icon|String|Icon of notification.|Exclude file extensions| |alarm_sound_loop|Boolean|Value to set whether the alarm sounds repeatedly.|Default: true| |alarm_vibration|Boolean|Value to set whether the alarm will vibrate when it is activated.|Default: true| |alarm_noti_removable|Boolean|Value to set whether to end the alarm when an notification is clicked.|Default: true| |alarm_activate|Boolean|Value to set whether to activate the alarm.|Default: true|

Alarm Scheduling

This schedules an alarm. Make sure that alarm_time must be in HH:mm:00 format.

  • Hour(00 ~ 23)
  • Minute(00 ~ 59)
  • Second(00)
const alarm = {
  alarm_time: 12:30:00,   // HH:mm:00
  alarm_title: 'title',
  alarm_text: 'text',
  alarm_sound: 'sound',   // sound.mp3
  alarm_icon: 'icon',     // icon.png
  alarm_sound_loop: true,
  alarm_vibration: true,
  alarm_noti_removable: true,
  alarm_activate: true
};

Alarm.schedule(
  alarm,
  success => console.log(success),  // success message
  fail => console.log(fail)         // fail message
);

Alarm Searching

Alarm searching is provided in two ways.

One

This searches for an alarm.
You can access the alarm_id to obtain alarm information for that ID.

Alarm.search(
  id,
  success => console.log(success),  // alarm
  fail => console.log(fail)         // fail message
);

All

This searches for all alarms.

Alarm.searchAll(
  success => console.log(success),  // alarm list
  fail => console.log(fail)         // fail message
);

Alarm Modifying

This is almost identical to alarm scheduling, but must be additionally given alarm_id.
Alarm information for that ID will be changed.
If you want an alarm toggle, just change the alarm_activate.

const alarm = {
  alarm_id: 3,
  alarm_time: 15:27:00,   // HH:mm:00
  alarm_title: 'title modify',
  alarm_text: 'text modify',
  alarm_sound: 'sound3',  // sound.mp3
  alarm_icon: 'icon2',    // icon.png
  alarm_sound_loop: false,
  alarm_vibration: true,
  alarm_noti_removable: false,
  alarm_activate: true    // value for alarm toggle
};

Alarm.modify(
  alarm,
  success => console.log(success),  // success message
  fail => console.log(fail)         // fail message
);

Alarm Deleting

This deletes the alarm for that ID.
This also automatically cancels the alarm schedule.

Alarm.delete(
  id,
  success => console.log(success),  // success message
  fail => console.log(fail)         // fail message
);

Alarm Stopping

This turns off the alarm.
This means that the sound stops and the notification disappears.

Alarm.stop(
  success => console.log(success),  // success message
  fail => console.log(fail)         // fail message
);

Typescript

Typescript declaration types has been added in version 1.2.0, it provides a set of convenient types that can be used while writing a typescript RN app.

import Alarm, {AlarmScheduleType} from 'react-native-alarm-manager';

const alarm: AlarmScheduleType = {
  alarm_time: '15:27:00', // HH:mm:00
  alarm_title: 'title',
  alarm_text: 'text',
  alarm_sound: 'sound', // sound.mp3
  alarm_icon: 'icon', // icon.png
  alarm_sound_loop: false,
  alarm_vibration: true,
  alarm_noti_removable: false,
  alarm_activate: true, // value for alarm toggle
};

Alarm.schedule(
  alarm,
  success => console.log(success),
  fail => console.log(fail),
);
import Alarm, {AlarmType} from 'react-native-alarm-manager';

const alarm: AlarmType = {
  alarm_id: 3,
  alarm_time: '15:27:00', // HH:mm:ss
  alarm_title: 'title modify',
  alarm_text: 'text modify',
  alarm_sound: 'sound3', // sound3.mp3
  alarm_icon: 'icon2', // icon2.png
  alarm_sound_loop: false,
  alarm_vibration: true,
  alarm_noti_removable: false,
  alarm_activate: true, // value for alarm toggle
};

Alarm.modify(
  alarm,
  success => console.log(success),
  fail => console.log(fail),
);

Example

Alarm scheduling from the main page

alarm-scheduling

Alarm searching from the top toolbar

alarm-searching

Alarm modifying from the alarm list

alarm-modifying

Alarm deleting from the alarm list

alarm-deleting

Alarm toggling from the alarm list

alarm-toggling

Alarm stopping after activation

alarm-stopping

License

MIT