Skip to content

Commit f5a7044

Browse files
committed
updated README
1 parent af4142b commit f5a7044

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
11
# react-native-custom-timer-notification
22

3-
custom timer notification
3+
custom timer notification for react native 🔔
44

55
## Installation
66

77
```sh
88
npm install react-native-custom-timer-notification
99
```
1010

11+
<!-- <service android:name="com.reactnativecustomtimernotification.ForegroundService"/> -->
12+
AndroidManifest
13+
```xml
14+
15+
<receiver android:name="com.reactnativecustomtimernotification.NotificationEventReceiver" />
16+
<receiver android:name="com.reactnativecustomtimernotification.OnClickBroadcastReceiver" />
17+
<!--
18+
if foreground service used add this line
19+
-->
20+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
21+
<service android:name="com.reactnativecustomtimernotification.ForegroundService"/>
22+
```
1123
## Usage
24+
```payload``` sent will be received when click or canceled
25+
```title``` Title of the notification
26+
```body``` Body of the notification
27+
```id``` unique number
28+
```sec``` Time in seconds
1229

1330
```js
1431
import { multiply } from "react-native-custom-timer-notification";
1532

1633
// ...
34+
// onclick and cancel listner
35+
DeviceEventEmitter.addListener("notificationClick",event=>{
36+
console.log(event)
37+
})
1738

1839
const result = await TimerNotification({
19-
eventData: JSON.stringify("notificationOpen?.data"),
40+
payload: JSON.stringify("notificationOpen?.data"),
2041
title: "My notification",
2142
body:"Much longer text that cannot fit one line... ",
2243
id: 1,

android/src/main/java/com/reactnativecustomtimernotification/CustomTimerNotificationModule.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CustomTimerNotificationModule: ReactContextBaseJavaModule {
5454
params.putInt("id", extras!!.getInt("id"))
5555
params.putString("action", extras!!.getString("action"))
5656
params.putString("payload", extras!!.getString("payload"))
57-
sendEvent("sysModuleNotificationClick", params)
57+
sendEvent("notificationClick", params)
5858
} catch (e: Exception) {
5959
println(e)
6060
}
@@ -84,20 +84,20 @@ class CustomTimerNotificationModule: ReactContextBaseJavaModule {
8484
fun notificationPop(objectData:ReadableMap,remainingTime:String,visbleTimer:Boolean):NotificationCompat.Builder{
8585
val title = objectData.getString("title");
8686
val body = objectData.getString("body");
87-
val eventData = objectData.getString("eventData");
87+
val payload = objectData.getString("payload");
8888
val id =objectData.getInt("id");
8989

9090
val intent = Intent(myContext, NotificationEventReceiver::class.java)
9191
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
9292
intent.putExtra("id",id);
9393
intent.putExtra("action","press");
94-
intent.putExtra("payload",eventData);
94+
intent.putExtra("payload",payload);
9595
val pendingIntent = PendingIntent.getBroadcast(myContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
9696

9797
val onCancelIntent = Intent(myContext, OnClickBroadcastReceiver::class.java)
9898
onCancelIntent.putExtra("id",id);
9999
onCancelIntent.putExtra("action","cancel");
100-
onCancelIntent.putExtra("payload",eventData);
100+
onCancelIntent.putExtra("payload",payload);
101101
val onDismissPendingIntent =
102102
PendingIntent.getBroadcast(myContext, 0, onCancelIntent, 0)
103103

android/src/main/java/com/reactnativecustomtimernotification/ForegroundService.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ForegroundService : Service() {
4444

4545
val title = intent?.getStringExtra("title");
4646
val body = intent?.getStringExtra("body");
47-
val eventData = intent?.getStringExtra("eventData");
47+
val payload = intent?.getStringExtra("payload");
4848
val id:Int? = intent?.getIntExtra("id",0)
4949
println(id)
5050

@@ -55,14 +55,14 @@ class ForegroundService : Service() {
5555
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
5656
intent.putExtra("id",id);
5757
intent.putExtra("action","press");
58-
intent.putExtra("payload",eventData);
58+
intent.putExtra("payload",payload);
5959
val pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
6060

6161

6262
val onCancelIntent = Intent(this, OnClickBroadcastReceiver::class.java)
6363
onCancelIntent.putExtra("id",id);
6464
onCancelIntent.putExtra("action","cancel");
65-
onCancelIntent.putExtra("payload",eventData);
65+
onCancelIntent.putExtra("payload",payload);
6666
val onDismissPendingIntent =
6767
PendingIntent.getBroadcast(this, 0, onCancelIntent, 0)
6868

example/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import * as React from 'react';
22

33
import { StyleSheet, View, Text,DeviceEventEmitter } from 'react-native';
44
import { TimerNotification } from 'react-native-custom-timer-notification';
5-
DeviceEventEmitter.addListener("sysModuleNotificationClick",event=>{
5+
DeviceEventEmitter.addListener("notificationClick",event=>{
66
console.log(event)
77
})
88
export default function App() {
99
const [result, setResult] = React.useState<number | undefined>();
1010

1111
React.useEffect(() => {
1212
TimerNotification({
13-
eventData: JSON.stringify("notificationOpen?.data"),
13+
payload: JSON.stringify("notificationOpen?.data"),
1414
title: "My notification",
1515
body:"Much longer text that cannot fit one line... ",
1616
id: 160211114,
17-
sec:60,
17+
sec:1800,
1818
remove:false, // optional
1919
foreground:false,
2020

0 commit comments

Comments
 (0)