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
  • 130,605
  • 17
  • 163
  • 193
Vora
  • 347
  • 2
  • 15

0 Answers0