0

Hello guys i successfully set push notification by changing of realtime database.For this i used below function to get notification when app is in background. But the problem is whenever notification is arrived there is no sound will play. So i add the sound :"default" according to this question https://stackoverflow.com/questions/37959588/no-notification-sound-when-sending-notification-from-firebase-in-android

Here is my error image enter image description here Here is my function

'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notifications/{receiver_user_id}/{notification_id}')
.onWrite((data, context) =>
{
 const receiver_user_id = context.params.receiver_user_id;
 const notification_id = context.params.notification_id;
 console.log('We have a notification to send to :' , receiver_user_id);
 if (!data.after.val()) 
 {
 console.log('A notification has been deleted :' , notification_id);
 return null;
 }
 const DeviceToken = admin.database().ref(`/Users/${receiver_user_id}/device_token`).once('value');
 return DeviceToken.then(result => 
 {
 const token_id = result.val();
 const payload = 
 {
 notification:
 {
 title: "New Chat Request",
 body: `you have a new Chat Request, Please Check.`,
 icon: "default"
 sound: "default"... ***added for default sound***
 }
 };
 return admin.messaging().sendToDevice(token_id, payload)
 .then(response => 
 {
 console.log('This was a notification feature.');
 });
 });
});
Alex Mamo
139k18 gold badges171 silver badges202 bronze badges
asked Jul 24, 2019 at 7:42
9
  • 1
    You are missing a , in the line before sound: .... Commented Jul 24, 2019 at 7:50
  • Also I am pretty sure this is just for StackOverflow, but just in case: Remove ... ***added for default sound*** too or replace it with a comment like: // ... ***added for default sound***. Commented Jul 24, 2019 at 7:50
  • Also, I am not sure, but your Promise handling does not look very ... Promising. (I'll find myself out) Commented Jul 24, 2019 at 7:52
  • icon: "default", sound: "default" You need to put a , in between those, otherwise it wont know that it is a new property. In JavaScript it is best practice to use ' ' over " ". Commented Jul 24, 2019 at 7:55
  • still sound is not playing while notifi Commented Jul 24, 2019 at 7:58

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.