FCM no sound from notification

Asked by At

I am setting up an application server in junction with FCM to send alerts to Android devices. I have followed multiple tutorials or stack questions on how to resolve no notification tone and the thing that I keep coming back to is the "notification" vs "data" message payload. I have tried this on emulators, physical devices with the same outcome. (no notification tone, no wake_lock screen, no alert while app in foreground). I trying to just tackle these one at a time so I am focusing on the tone.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

        android:resource="@drawable/ic_stat_ic_notification" />
        android:resource="@color/colorAccent" />
        android:value="@string/default_notification_channel_id" />
            <action android:name="com.google.firebase.MESSAGING_EVENT" />

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />



package com.hctechintegrations.inovonics;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;

 * NOTE: There can only be one service in each app that receives FCM messages. If multiple
 * are declared in the Manifest then the first one will be chosen.
 * In order to make this Java sample functional, you must remove the following from the Kotlin messaging
 * service in the AndroidManifest.xml:
 * <intent-filter>
 *   <action android:name="com.google.firebase.MESSAGING_EVENT" />
 * </intent-filter>
public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = "MyFirebaseMsgService";

     * Called when message is received.
     * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
    // [START receive_message]
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        String channelId = "Default";
        NotificationCompat.Builder builder = new  NotificationCompat.Builder(this, channelId)
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
        manager.notify(0, builder.build());

    // [START on_new_token]

     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. Note that this is called when the InstanceID token
     * is initially generated so this is where you would retrieve the token.
    public void onNewToken(String token) {
        Log.d(TAG, "Refreshed token: " + token);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
    // [END on_new_token]

     * Schedule async work using WorkManager.
    private void scheduleJob() {
        // [START dispatch_job]
        OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(MyWorker.class)
        // [END dispatch_job]

     * Handle time allotted to BroadcastReceivers.
    private void handleNow() {
        Log.d(TAG, "Short lived task is done.");

     * Persist token to third-party servers.
     * Modify this method to associate the user's FCM InstanceID token with any server-side account
     * maintained by your application.
     * @param token The new token.
    private void sendRegistrationToServer(String token) {
        // TODO: Implement this method to send token to your app server.

     * Create and show a simple notification containing the received FCM message.
     * @param messageBody FCM message body received.
    private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,

        String channelId = getString(R.string.default_notification_channel_id);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId,
                    "Channel human readable title",

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());


var admin = require("firebase-admin");

var serviceAccount = require("/path/to/serviceAccountKey.json");//my actual path

  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://mattsaiko-inovonics.firebaseio.com"

var registrationToken = "ccOwyYgdwmQ:APA91bF5btMIpbozKU0WEzSl580viv3QTekdeHk9SYqrfF4R5r9V7_9gA2vq5YQJaNQb9UZZP29lppXN1S49NA516EjWStsOWZ_qQRp0tZ29RZrEq2g9cz8LucsduAwveA636tTPWK1A";

var payload = {
  notification: {
    title: "Account Deposit",
    body: "A deposit to your savings account has just cleared.",
    priority: "high",
    sound: "default"
  data: {
    account: "Savings",
    balance: "$3020.25"

 var options = {
  timeToLive: 60 * 60 *24

admin.messaging().sendToDevice(registrationToken, payload, options)
  .then(function(response) {
    console.log("Successfully sent message:", response);
  .catch(function(error) {
    console.log("Error sending message:", error);

I have tried to change the payload notification to data and removed the data line. I have added the priority and sound to options. Every stack question I found says to replace "notification" in my send.js to "data" when I do that I do not get any message on the device but I do get a sent successfully notification on my server.

Thank you

0 Answers