i am having an android app which uses firebase as a backend.
Using firebase cloud function as soon as the database is having change at a specific node, the notification triggers.
But I am not able to figure out how to open specific activity according to the change at a specific node.
I am having 5 activities and 5 node at database, the activity which should get open through notification should be the activity which corresponds to the change at the specific node.
but right now it opens the default activity.
I am not able to figure that how notification will contain the information of opening the specific activity in their payload as the notification are delivered through firebase cloud functions.
the example file of index.js is pasted below, for changes in one child node only.
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendPowerNotification = functions.database.ref("/Matrimony").onWrite((event) => {
const data = event.data;
console.log('New Issue added');
if (!data.changed()) {
return;
}
const status = data.val();
//const onOff = status ? "on": "off";
const author = event.params.author;
const name = author.val();
const payload = {
notification: {
title: 'SahuSmaj : New Matrimony Post',
body: `New biodata entered,check it out`,
sound: "default"
click_action: "MATRIMONY"
}
};
const options = {
priority: "high",
timeToLive: 60 * 60 * 24 //24 hours
};
console.log('Sending notifications');
return admin.messaging().sendToTopic("matrimony", payload, options);
});
executing the above code show this error :
Error: Error occurred while parsing your function triggers.
/private/var/folders/sf/2spqs2n1493d506bj06wj0zw0000gn/T/fbfn_1018VUGx2TTMO1y8/index.js:33
click_action : "MATRIMONY"
^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:16:9)
at Module._compile (module.js:570:32)
I had made the changes in my AndroidManifest.xml for opening specific notification using Android Filter.
<intent-filter>
<action android:name="MATRIMONY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>