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-android-notification

v1.0.0

Published

A react-native module which is used to schedule and manage local notifications.

Downloads

5

Readme

react-native-android-notification

Getting Started

Installation

Using npm

$ npm install react-native-android-notification --save

Using yarn

$ yarn add react-native-android-notification

Linking

There are two options for linking:

1. Automatic

react-native link react-native-android-notification

2. Manual

If the automatic linking fails for some reason, you can do the linking manually as follows:

  • add the following to yourAppName/android/settings.gradle file:
	include ':react-native-android-notification'
	project(':react-native-android-nofication').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-notification/android')
  • add the following inside the dependencies closure of yourAppName/android/app/build.gradle file:
	implementation project(':react-native-android-notification')
  • add the following to your MainApplication.java file:
	import com.sysapps.notification.NotifPackage;

and also,

   @Override
   protected List<ReactPackage> getPackages() {
   	return Arrays.<ReactPackage>asList(
   		new MainReactPackage(),
   		....
   		new NotifPackage()                    <== Add this
   	);
   }

Usage

To schedule and manage notifications, first import the module to your app like so:

import { Notification } from 'react-native-android-notification';

After this, you can call any of the functions stated below to schedule an alarm.

Functions

    schedule(Object options)
    update(Object options)
    refer(String id)
    cancel(String id)
    cancelAll()    

Events

	import { DeviceEventEmitter } from "react-native";

	componentDidMount() {
		DeviceEventEmitter.addListener('onNotification', (e) => {
			const response = JSON.parse(e);
			console.log(response);
		});
  	}

If you want to handle the event while the app is in the background, you have to add the following at the bottom of your javascript file. You should also register the EventEmitter service in your AndroidManifest.xml file as described in the Permissions section.

    import { AppRegistry } from "react-native";

    AppRegistry.registerHeadlessTask('SysappsEventNotification', () => async (e) => {
        console.log(taskData);
    });

The response data sent via the event emitter is the string representation of the original object parameter passed to the schedule() function. Note that, only primitive data will be persisted and sent back as a response.

Permissions

	<service android:name="com.sysapps.notification.alarm.AlarmService"
    		android:permission="android.permission.BIND_JOB_SERVICE" />
   <service android:name="com.sysapps.notification.alarm.EventEmitter"/>
	<uses-permission android:name="android.permission.WAKE_LOCK"/>
	<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
	<uses-permission android:name="android.permission.VIBRATE"/>

Description

schedule(Object options):

You can also add any other key-value pairs in addition to the above so that you can recover them when the event is fired at the time of notification. These key-value pairs should be of primitive data types.

Sample code snippet
       import { Notification } from 'react-native-android-notification';
       ....
       ....
       _scheduleNotification = () => {
            const date = new Date(2019, 11, 1, 8, 30, 0); // Dec 01 2019 @ 8:30:00 AM        	 
        	const params = { 
                	"channelId": "abc123", 
                	"date": date.getTime(), 
                	"title": "my title", 
                	"content" : "my content", 
                	"key1": "value1", 
                	"key2": false, 
               		"key3": 14123 
        	};
        	Notification.schedule(params);
        } 

update(Object options):

Sample code snippet
        import { Notification } from 'react-native-android-notification';
       	....
       	....
	_updateNotif_abc123 = () => {
            const date = new Date(2019, 11, 2, 8, 30, 0); // Dec 02 2019 @ 8:30:00 AM  
        	Notification.update({ "channelId": "abc123", "date": date.getTime() });        	
        } 

refer(String channelId):

Sample code snippet
            import { Notification } from 'react-native-android-notification';
       		....
       		....
	    _referScheduledNotif = async () => {
                const params = await Notification.refer("abc123");
                console.log(params);
            } 

cancel(String channelId):

Sample code snippet
            import { Notification } from 'react-native-android-notification';
       		....
       		....
	    _cancelNotification = () => {
                Notification.cancel("abc123");
            } 

cancelAll():

Sample code snippet
	    import { Notification } from 'react-native-android-notification';
       		....
       		....
            _cancelAllNotifications = () => {
                Notification.cancelAll();
            } 

Issues or suggestions?

If you have any issues or if you want to suggest something , you can write it here.

Additional info

This is a component of a more comprehensive react-native-system-applications module developed by the same author.