# Advanced Android notifications

**URL:** <https://discourse.nodered.org/t/advanced-android-notifications/23588>\
**Category:** Share Your Projects\
**Created:** [24 March 2020 22:00 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588 "2020-03-24T22:00:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![eschava](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eschava/32/33_2.png) [@eschava](https://discourse.nodered.org/u/eschava)\
**Post date:** [24 March 2020 22:00 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/1 "2020-03-24T22:00:50Z")

</div>

Hi all,

I've finally found time to implement the service I had been dreaming about for a long time.  
Please welcome - [FireNotify](https://play.google.com/store/apps/details?id=com.eschava.firenotify) - Android application with free unlimited advanced notifications

It has API based on the free Google FCM service and allows you to send notifications to your Android phone which could be:

- ordinary (text, optional subject)
- silent
- grouped (several messages from the same group could be collapsed)
- persistent (cannot be dismissed by user)
- replaceable (new notification replaces previous having the same id)
- having custom images
- actionable (notification with action button(s) generating Node-Red message when pressed)  
and so on

To send notifications from Node-Red the [node-red-contrib-fcm-push-node](https://flows.nodered.org/node/node-red-contrib-fcm-push-node) node could be used.  
Currently, it requires to specify FCM server key in FCM\_SERVER\_KEY environment variable (e.g. using settings.js instruction like `process.env.FCM_SERVER_KEY = "AAAAaO...";` )

Use the next key for FireNotify service:

```auto
FCM_SERVER_KEY=AAAAaOmKSfc:APA91bGabQ9tUXtf5iUOycizl7Wpw0E875EiyxC8E9C2MyfMuG2anvfErYjrwEr4xFsoIVoIalqG4IupliY9436j4HNaL8jgDPEag2S0nSuI3TeU9TTbaK2bj8CFUVBDS6KCZib6Zo0X

```

And below is JSON content of the message payload that could be used to send a simple message to your phone:

```auto
{
	"data": 
	{
		"text": "Hello"
	},
	"to" : "TOKEN_FROM_ANDROID_APPLICATION",
	"priority" : "high"
}

```

("priority" : "high" is a kind of hack for FCM service to deliver notification message even to the sleeping phone)

All supported parameters are present at the [GitHub page](https://github.com/eschava/FireNotify-Android) of the project

To send an actionable notification you will need:

1. Install [node-red-contrib-fcm-receive-node](https://flows.nodered.org/node/node-red-contrib-fcm-receive-node) node to receive FCM messages, add it, register connection for the same FCM server key and check token printed to the Node-Red console

2. Make the next changes to the JSON of the message payload:

```auto
{
	"data": 
	{
		"text": "Hello",
		"to": "TOKEN_FROM_NODE_RED",
		"actions": [
			{"title": "Press me", "data": {"action": "pressed"}}
		]
	},
	"to" : "TOKEN_FROM_ANDROID_APPLICATION",
	"priority" : "high"
}

```

And notification with single "Press me" action will appear on the screen. When action is pressed - "FCM receive" node will send message with content of "data" property of the action (payload.data.action = "pressed")

Enjoy!

P.S. I know that there could be some issues (for instance token in the Android application appears only on the second start) so your feedback is highly appreciated!

First example to import:

```auto
[{"id":"a9ca6f39.541e3","type":"inject","z":"9665c43f.7e5e38","name":"","topic":"","payload":"{\"data\":{\"text\":\"Hello\"},\"to\":\"TOKEN_FROM_ANDROID_APPLICATION\",\"priority\":\"high\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":40,"wires":[["1afd39b2.5788e6"]]},{"id":"1afd39b2.5788e6","type":"fcm-push","z":"9665c43f.7e5e38","name":"","x":640,"y":140,"wires":[]}]

```

Second example to import:

```auto
[{"id":"6d296b66.521c74","type":"inject","z":"9665c43f.7e5e38","name":"","topic":"","payload":"{\"data\":{\"text\":\"Hello\",\"to\":\"TOKEN_FROM_NODE_RED\",\"actions\":[{\"title\":\"Press me\",\"data\":{\"action\":\"pressed\"}}]},\"to\":\"TOKEN_FROM_ANDROID_APPLICATION\",\"priority\":\"high\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":90,"wires":[["1afd39b2.5788e6"]]},{"id":"1afd39b2.5788e6","type":"fcm-push","z":"9665c43f.7e5e38","name":"","x":640,"y":140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 March 2020 22:17 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/2 "2020-03-24T22:17:43Z")

</div>

Long term, are you planning to monetize this app/service?

---

<div class="post-metadata">

**Author:** ![eschava](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eschava/32/33_2.png) [@eschava](https://discourse.nodered.org/u/eschava)\
**Post date:** [24 March 2020 22:19 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/3 "2020-03-24T22:19:34Z")

</div>

No, all sources are open, service is provided by Google and they claim that it will be free

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 March 2020 22:21 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/4 "2020-03-24T22:21:21Z")

</div>

This looks like a really useful contribution @eschava, thanks for sharing.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 March 2020 22:43 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/5 "2020-03-24T22:43:48Z")

</div>

> [@eschava](#):
>
> Currently, it requires to specify FCM application token in FCM\_SERVER\_KEY environment variable  
> Use the next key for FireNotify service:
> 
> ```auto
> FCM_SERVER_KEY=AAAAaOmKSfc:APA91bGabQ9tUXtf5iUOycizl7Wpw0E875EiyxC8E9C2MyfMuG2anvfErYjrwEr4xFsoIVoIalqG4IupliY9436j4HNaL8jgDPEag2S0nSuI3TeU9TTbaK2bj8CFUVBDS6KCZib6Zo0X
> 
> ```

Where is this added? I've loaded your example push flow, added my Android app token, but not working, I assume because I haven't added the FCM\_SERVER\_KEY ??

![snip](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4f3b0fe8c99ef41df598fac456ec2fb43e509805.jpeg)

---

<div class="post-metadata">

**Author:** ![eschava](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eschava/32/33_2.png) [@eschava](https://discourse.nodered.org/u/eschava)\
**Post date:** [24 March 2020 23:09 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/6 "2020-03-24T23:09:17Z")

</div>

It's OS environment variable and it could be set using export command for Linux or set command for Windows before starting Node-Red process

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 March 2020 23:22 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/7 "2020-03-24T23:22:16Z")

</div>

Aah right, hopefully future development will avoid having to do this.  
I'll come back at a later time.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 March 2020 00:45 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/8 "2020-03-25T00:45:11Z")

</div>

Easier to set it in settings.js as you can then use Node.js's feature to set environment variables - that is cross-platform.

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [25 March 2020 07:54 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/9 "2020-03-25T07:54:00Z")

</div>

This is awesome, thanks! Haven't yet tried it so I am not sure if already implemented but does firenotify also provide a history overview of notifications received?

---

<div class="post-metadata">

**Author:** ![eschava](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eschava/32/33_2.png) [@eschava](https://discourse.nodered.org/u/eschava)\
**Post date:** [25 March 2020 08:16 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/10 "2020-03-25T08:16:46Z")

</div>

Not yet. I have this in ideas for further development but now you can use 3rd party applications storing history of notifications for any app  
You can choose any from [https://play.google.com/store/search?q=notification%20history](https://play.google.com/store/search?q=notification%20history) and share your expirience

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [25 March 2020 09:16 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/11 "2020-03-25T09:16:29Z")

</div>

Got t to work! However when trying out the receive node, no token was printed to node red's console. I got this instead :):

```auto
(node:23977) UnhandledPromiseRejectionWarning: StatusCodeError: 400 - "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Request contains an invalid argument.\",\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n"
    at new StatusCodeError (/home/pi/.node-red/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/home/pi/.node-red/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/home/pi/.node-red/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/home/pi/.node-red/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/home/pi/.node-red/node_modules/request/request.js:1154:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/home/pi/.node-red/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)
(node:23977) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:23977) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [25 March 2020 09:54 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/12 "2020-03-25T09:54:46Z")

</div>

> [@TotallyInformation](#):
>
> Easier to set it in settings.js

~~Like this?~~ - see post below

```auto
process.env.FCM_SERVER_KEY=AAAAaOmKSfc:APA91bGabQ9tUXtf5iUOycizl7Wpw0E875EiyxC8E9C2MyfMuG2anvfErYjrwEr4xFsoIVoIalqG4IupliY9436j4HNaL8jgDPEag2S0nSuI3TeU9TTbaK2bj8CFUVBDS6KCZib6Zo0X;

```

Added to the top of settings.js

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [25 March 2020 10:08 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/13 "2020-03-25T10:08:13Z")

</div>

like this 🙂

```auto
process.env.FCM_SERVER_KEY="AAAAaOmKSfc:APA91bGabQ9tUXtf5iUOycizl7Wpw0E875EiyxC8E9C2MyfMuG2anvfErYjrwEr4xFsoIVoIalqG4IupliY9436j4HNaL8jgDPEag2S0nSuI3TeU9TTbaK2bj8CFUVBDS6KCZib6Zo0X";

```

Note the double quotes.

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [25 March 2020 10:32 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/14 "2020-03-25T10:32:30Z")

</div>

Is there a way to send a url, which opens when clicked on the notification?

---

<div class="post-metadata">

**Author:** ![eschava](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eschava/32/33_2.png) [@eschava](https://discourse.nodered.org/u/eschava)\
**Post date:** [25 March 2020 11:22 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/15 "2020-03-25T11:22:58Z")

</div>

> [@realjax](#):
>
> Request contains an invalid argument

There are different explanation on the internet about this error and some of them are about incorrect FCM server key, could you please recheck whether it is correct?

---

<div class="post-metadata">

**Author:** ![eschava](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eschava/32/33_2.png) [@eschava](https://discourse.nodered.org/u/eschava)\
**Post date:** [25 March 2020 11:24 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/16 "2020-03-25T11:24:35Z")

</div>

> Is there a way to send a url, which opens when clicked on the notification?

Good idea. And I would rather add the url to open as an option for an action, not for clicking on the notification itself. What do you think?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 March 2020 11:40 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/17 "2020-03-25T11:40:46Z")

</div>

Yes - we have enough trouble with dodgy links as it is... so allowing a confirmation/option first is sensible

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [25 March 2020 12:14 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/18 "2020-03-25T12:14:50Z")

</div>

Yes, I had the wrong key. I think :). Now it throws this error:

```auto

(node:24386) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/home/pi/.node-red/fcm-receive/bc4b8b5d.ba9948/fcm.cred'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.writeFileSync (fs.js:1299:33)
    at FcmConnection (/home/pi/.node-red/node_modules/node-red-contrib-fcm-receive-node/fcm-connection.js:28:20)
    at <anonymous>
(node:24386) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

```

Seems it tries to write to a file which is not created yet?

---

<div class="post-metadata">

**Author:** ![eschava](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eschava/32/33_2.png) [@eschava](https://discourse.nodered.org/u/eschava)\
**Post date:** [25 March 2020 12:50 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/19 "2020-03-25T12:50:37Z")

</div>

> Seems it tries to write to a file which is not created yet?

Please check whether /home/pi/.node-red/fcm-receive/bc4b8b5d.ba9948/ folder exists  
I'm not an expert in node.js development and wrote this plugin using stackoverflow-driven methodology 🙂

That directory should be created by previous instruction  
fs.mkdirSync(dir, { recursive: true });

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [25 March 2020 12:54 UTC](https://discourse.nodered.org/t/advanced-android-notifications/23588/20 "2020-03-25T12:54:51Z")

</div>

Folder doesn't exist, so something is going off there. :(. I'll try creating it manually to see what happens then.

Edit: yep, that worked. Now I get a token.

Edit 2: And the message is received back in Node Red, pretty nice!! Although it is not very clear on my phone that I 'pressed' a button in the notification, which caused me pressing it tenfold 🙂

 ![Screenshot_2020-03-25-14-08-29-297_com.teslacoilsw.launcher](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/6097cf635fc7bf0637889e3234d69f7edeeb775c.jpeg)

Edit 3: Every message received back also throws an error in the console:

```auto
{ Error: read ECONNRESET
    at TLSWrap.onread (net.js:622:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }

```

[Next page](https://discourse.nodered.org/t/advanced-android-notifications/23588.md?page=2)
