Search code examples
androidfirebasefirebase-cloud-messagingwear-os

Firebase cloud messages are not delivered to Wear OS device


I have a problem receiving Firebase push messages to a watch that operates Wear OS. This happens when watch is paired with a smartphone via bluetooth (no Wi-fi connection). If Wi-fi is active on the watch, then messages are delivered just fine.

I'm sending data message via POST request using FCM endpoint: https://fcm.googleapis.com/fcm/send

And the message payload itself looks like this:

{
    "priority" : "high",
    "to" : "/topics/myTopic",
    "data" : {
        "key1" : "val1",
        "key2" : "val2"
        "key3" : "val3"
    }
}

I registered service like usual:

    <service android:name=".data.fcm.MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

And listen to messages like always:

override fun onMessageReceived(remoteMessage: RemoteMessage?) {
        // Check whether message contains a data payload.
        if (remoteMessage?.data!!.isNotEmpty()) {
            Timber.d("Message data payload: ${remoteMessage.data}")
            ....
        }
    }
}

I should note that Firebase Database is working perfectly on a watch, that is connected just via the bluetooth to the phone. But FCM does not.

Any ideas are greatly appreciated.


Solution

  • It could be due to the blocked ports used by FCM on the paired phone. If phone is connected via Wifi, and FCM ports (5228, 5229, 5230)are blocked there, messages won't be delivered. https://firebase.google.com/docs/cloud-messaging/concept-options#ports_and_your_firewall